diff --git a/compiler/AST/symbol.cpp b/compiler/AST/symbol.cpp index 11307ce0e444..71aec4933dc0 100644 --- a/compiler/AST/symbol.cpp +++ b/compiler/AST/symbol.cpp @@ -2247,7 +2247,7 @@ const char* toString(VarSymbol* var, bool withType) { SymExpr* dstSe = toSymExpr(c->get(1)); SymExpr* srcSe = toSymExpr(c->get(2)); if (dstSe && srcSe && dstSe->symbol() == sym) { - sym = singleDef->symbol(); + sym = srcSe->symbol(); continue; } } diff --git a/compiler/resolution/functionResolution.cpp b/compiler/resolution/functionResolution.cpp index 8610cab2bbe9..cbc254f4f625 100644 --- a/compiler/resolution/functionResolution.cpp +++ b/compiler/resolution/functionResolution.cpp @@ -4762,14 +4762,24 @@ static bool obviousMismatch(CallExpr* call, FnSymbol* fn) { return (isMethodCall != isMethodFn); } +static bool isSymExprTypeVar(Expr* e) { + if (SymExpr* se = toSymExpr(e)) { + return se->symbol()->hasFlag(FLAG_TYPE_VARIABLE); + } + + return false; +} + // returns true if the error was issued static bool maybeIssueSplitInitMissingTypeError(CallInfo& info, Vec& visibleFns) { // Check for uninitialized values (with type dtSplitInitType) bool foundUnknownTypeActual = false; for_actuals(actual, info.call) { + bool isTypeVariable = isSymExprTypeVar(actual); Type* t = actual->getValType(); - if (t == dtSplitInitType || t->symbol->hasFlag(FLAG_GENERIC)) { + if (t == dtSplitInitType || + (!isTypeVariable && t->symbol->hasFlag(FLAG_GENERIC))) { foundUnknownTypeActual = true; } } @@ -4790,8 +4800,10 @@ static bool maybeIssueSplitInitMissingTypeError(CallInfo& info, if (anyTypeNotEstablished) { bool printedError = false; for_actuals(actual, info.call) { + bool isTypeVariable = isSymExprTypeVar(actual); Type* t = actual->getValType(); - if (t == dtSplitInitType || t->symbol->hasFlag(FLAG_GENERIC)) { + if (t == dtSplitInitType || + (!isTypeVariable && t->symbol->hasFlag(FLAG_GENERIC))) { if (SymExpr* se = toSymExpr(actual)) { CallExpr* call = userCall(info.call); splitInitMissingTypeError(se->symbol(), call, false); diff --git a/test/types/records/split-init/split-init-error-bug/Foo.chpl b/test/types/records/split-init/split-init-error-bug/Foo.chpl new file mode 100644 index 000000000000..4e772f50a05b --- /dev/null +++ b/test/types/records/split-init/split-init-error-bug/Foo.chpl @@ -0,0 +1,7 @@ +module Foo { + class foo { + var size : int(64); + param isWeighted : bool; + var arrDom : domain(1) = {1..(if isWeighted then size else 0)}; + } +} diff --git a/test/types/records/split-init/split-init-error-bug/Foo.notest b/test/types/records/split-init/split-init-error-bug/Foo.notest new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/test/types/records/split-init/split-init-error-bug/FooUser.chpl b/test/types/records/split-init/split-init-error-bug/FooUser.chpl new file mode 100644 index 000000000000..be8fa795f30b --- /dev/null +++ b/test/types/records/split-init/split-init-error-bug/FooUser.chpl @@ -0,0 +1,6 @@ +module FooUser { + use Foo; + proc Use_Foo(type inType : foo, in data : inType, type outType : real(?), outWeights : [] outType) { + //Do stuff + } +} diff --git a/test/types/records/split-init/split-init-error-bug/FooUser.notest b/test/types/records/split-init/split-init-error-bug/FooUser.notest new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/test/types/records/split-init/split-init-error-bug/Reproducer.chpl b/test/types/records/split-init/split-init-error-bug/Reproducer.chpl new file mode 100644 index 000000000000..fe291c1d7438 --- /dev/null +++ b/test/types/records/split-init/split-init-error-bug/Reproducer.chpl @@ -0,0 +1,11 @@ +module Reproducer { + use Foo; + use FooUser; + proc main() { + var myFoo : foo(false); + var retDom : domain(1) = {1..10}; + var retArr : [retDom] real(32); + //There is only one CallExpr in Reproducer.main, so the loop seems to trigger on this + Use_Foo(foo(false), myFoo, real(32), retArr); + } +} diff --git a/test/types/records/split-init/split-init-error-bug/Reproducer.good b/test/types/records/split-init/split-init-error-bug/Reproducer.good new file mode 100644 index 000000000000..36e04092c85c --- /dev/null +++ b/test/types/records/split-init/split-init-error-bug/Reproducer.good @@ -0,0 +1,5 @@ +Reproducer.chpl:4: In function 'main': +Reproducer.chpl:5: error: cannot default-initialize a variable with generic type +Reproducer.chpl:5: note: 'myFoo' has generic type 'foo(false)' +Reproducer.chpl:5: note: cannot find initialization point to split-init this variable +Reproducer.chpl:9: note: 'myFoo' is used here before it is initialized