Skip to content

Commit

Permalink
Tests document issue in lang::rascal::grammar::analyze::Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Aug 6, 2024
1 parent 020aab1 commit 37e47cb
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,26 @@ test bool listMatchInOR() {
|| strt() := x
;
return unquotable(\strt());
}
}


data Symbol
= sym(str name)
| label(str name, Symbol sym)
;

// Simplified version from lang::rascal::grammar::analyze::Dependency
set[Symbol] symbolDependenciesOld(set[Symbol] sses) =
{ from | s <- sses, bprintln(s), (label(_,Symbol from) := s || Symbol from := s)};

// Test for original version (with probably unintended result)
@ignoreCompiler{Generates incorrect code}
test bool symbolDependenciesOld1()
= symbolDependenciesOld({sym("a"), label("x", sym("b"))}) == {sym("a"), sym("b"), label("x", sym("b"))};

// Rewritten version with intended output, compiler behaves well on it
set[Symbol] symbolDependenciesNew(set[Symbol] sses) =
{ from | s <- sses, bprintln(s), Symbol from := ((label(_,Symbol f) := s) ? f : s) };

test bool symbolDependenciesNew1()
= symbolDependenciesNew({sym("a"), label("x", sym("b"))}) == {sym("a"), sym("b")};

0 comments on commit 37e47cb

Please sign in to comment.