Skip to content

[Bug]: Default value verification of params doesn't respect previous substitutions #27973

@DanilaFe

Description

@DanilaFe

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:

} 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions