- 
                Notifications
    
You must be signed in to change notification settings  - Fork 434
 
Open
Labels
Description
The logic that's responsible for computing the type of a param/type formal from its default value does not respect preceding substitutions. Thus, the following program:
proc foo(type arg1, param arg2: arg1 = "hello") where isIntType(arg2.type) {
  compilerWarning("arg1 constrains arg2's type to be: " + arg1:string);
  compilerWarning("arg2's final value ends up " + arg2:string);
}
foo(int);Fails to resolve with:
paramignoressub.chpl:1: In module 'paramignoressub':
paramignoressub.chpl:5: error: unresolved call 'foo(type int(64))'
paramignoressub.chpl:1: note: this candidate did not match: foo(type arg1, param arg2: arg1 = "hello") [319104]
paramignoressub.chpl:1: note: because where clause evaluated to false
paramignoressub.chpl:5: note: unresolved call had id 319147
This is even though arg2 is explicitly constrained to be arg1, which is int. The responsible logic is likely:
chapel/compiler/resolution/ResolutionCandidate.cpp
Lines 504 to 505 in d03955d
| } else if (formal->type->symbol->hasFlag(FLAG_GENERIC) == true && | |
| canInstantiate(se->symbol()->type, formal->type) == false) { | 
Without the where clause, the compiler eventually reports an error for instantiating an integer from a string. However, this is not before the where clause receives an incorrect type.
Associated future tests
test/functions/default-arguments/param-default-ignores-substitutions.chpl (#27979)