Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ public Bindings matchRascalTypeParams0(AType r, AType s, Bindings b) {
return matchRascalTypeParams0(getFunctionReturnType(r), getFunctionReturnType(s), b);
}

// A constructor can be used as a function (and vice versa during unification):
// match the parameter types with the fields, and the return type with the ADT
if ( isFunctionAType(r) && isConstructorAType(s) ) {
b = matchRascalTypeParams0(getFunctionArgumentTypesAsTuple(r), getConstructorArgumentTypesAsTuple(s), b);
return matchRascalTypeParams0(getFunctionReturnType(r), getConstructorResultType(s), b);
}

if ( isConstructorAType(r) && isFunctionAType(s) ) {
b = matchRascalTypeParams0(getConstructorArgumentTypesAsTuple(r), getFunctionArgumentTypesAsTuple(s), b);
return matchRascalTypeParams0(getConstructorResultType(r), getFunctionReturnType(s), b);
}

// For tuples, check the arity then match the item types
if ( isTupleAType(r) && isTupleAType(s) && getTupleFieldCount(r) == getTupleFieldCount(s) ) {
rfields = getTupleFieldTypes(r);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,28 @@ test bool SyntaxConstructorAsArgNotOk(){
void f(void(A) _) { }

void main(){ f(a); }");
}
}
// https://github.com/usethesource/rascal/issues/2908
test bool ADTConstructorAsArgToHigherOrderGenericFunctionOk(){
return checkModuleOK("
module ADTConstructorAsArgToHigherOrderGenericFunctionOk
data Msg = editField(str field, str val);

&T(&V) partial(&T(&U0, &V) f, &U0 u0) = &T(&V v) { return f(u0, v); };

void show(Msg(str) _) { }

void main(){ show(partial(editField, \"x\")); }");
}

test bool ADTConstructorAsArgToHigherOrderGenericFunctionNotOk(){
return argumentMismatchInModule("
module ADTConstructorAsArgToHigherOrderGenericFunctionNotOk
data Msg = editField(str field, str val);

&T(&V) partial(&T(&U0, &V) f, &U0 u0) = &T(&V v) { return f(u0, v); };

void show(int(str) _) { }

void main(){ show(partial(editField, \"x\")); }");
}
Loading