Skip to content

Commit 0c3f4e2

Browse files
committed
Make typed variable pattern dependent on return type
- This is needed for proper execution order - This is rather coarse solution. Maybe move this to cases for type parameters?
1 parent eca6b2e commit 0c3f4e2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ void collect(current: (Pattern) `<Type tp> <Name name>`, Collector c){
9393
collect(tp, c);
9494
if(tp is function) c.leaveScope(current);
9595

96-
c.calculate("typed variable pattern", current, [tp], AType(Solver s){ return s.getType(tp)[alabel=uname]; });
96+
functionScopes = c.getScopeInfo(functionScope());
97+
if(isEmpty(functionScopes)){
98+
throw rascalCheckerInternalError(getLoc(current), "No surrounding function scope found for typed variable pattern");
99+
}
100+
for(<_, scopeInfo> <- functionScopes){
101+
if(signatureInfo(Type returnType) := scopeInfo){
102+
c.calculate("typed variable pattern", current, [tp, returnType], AType(Solver s){ return s.getType(tp)[alabel=uname]; });
103+
break;
104+
} else {
105+
throw rascalCheckerInternalError(getLoc(current), "Inconsistent info from function scope: <scopeInfo>");
106+
}
107+
}
108+
97109
if(!isWildCard(uname)){
98110
c.push(patternNames, <uname, getLoc(name)>);
99111
orScopes = c.getScopeInfo(orScope());

0 commit comments

Comments
 (0)