Skip to content

Commit

Permalink
More clever handling of variable becomes pattern. Fixes #1996
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Jul 5, 2024
1 parent 764561e commit 6fc0e16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,13 @@ void collect(current: (Pattern) `<Name name> : <Pattern pattern>`, Collector c){
} else {
c.push(patternNames, <uname, getLoc(name)>);
scope = c.getScope();
c.define(uname, formalOrPatternFormal(c), name, defLub([pattern], AType(Solver s) { return getPatternType(pattern, avalue(), scope, s); }));
c.define(uname, formalOrPatternFormal(c), name,
defLub([pattern], AType(Solver s) {
try{
return s.getType(pattern);
} catch _:
return getPatternType(pattern, avalue(), scope, s);
}));
}
collect(pattern, c);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
module lang::rascalcore::compile::Examples::Tst4

import IO;
//alias T = tuple[int, str];
void main() {
//set[tuple[int, str]] r = {};

data Foo = foo(int x);
list[Foo] foos = [foo(1), foo(2), foo(3)];
// Error
// `Initialization of `ts1` should be subtype of `rel[int, str]`, found `rel[value, value]``
//set[tuple[int, str]] ts1 = {t | t:<int _, _> <- r};

set[str] a = {};
set[str] b = { x| t: x <- a};

//// No errors
//set[T] ts2 = {t | t <- r};
//set[T] ts3 = {t | T t:<_, _> <- r};
//set[T] ts4 = {<i, s> | <i, s> <- r};
//set[T] ts5 = {t | t:<int _, str _> <- r};
}

void f() {
bool foo() = true;
println(foo(x) in foos);
// ^^^ Error: "Expected 0 argument(s), found 1"
}


//value main() = _f(3);

//data Tree;
Expand Down

0 comments on commit 6fc0e16

Please sign in to comment.