Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some (but not all) ambiguity errors make Rascal Document Symbols crash #560

Open
sungshik opened this issue Jan 18, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@sungshik
Copy link
Contributor

sungshik commented Jan 18, 2025

Context

Consider the following two modules:

module Ambiguous1

str s = "<x<0>><x<1>>";
module Ambiguous2

tuple[str] f(tuple[str] tup) = <tup<0>> when _ := tup;

Both modules give rise to an ambiguity error in the REPL, as reported in usethesource/rascal#2122 and usethesource/rascal#2125. However, in the UI, VS Code reports no errors for module Ambiguous1, while it reports the following error for Ambiguous2 (each time the module is changed, regardless of the change, as long as the definition of f is kept):

Image

Exception thrown

Undeclared field: signature for Tree
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredField|

Stacktrace:

org.rascalmpl.interpreter.staticErrors.UndeclaredField: Undeclared field: signature for Tree
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredField|
	at DocumentSymbols.?(/lang/rascal/lsp/DocumentSymbols.rsc:65)
	at org.rascalmpl.interpreter.result.ConstructorResult.fieldAccess(ConstructorResult.java:120)
	at org.rascalmpl.interpreter.result.ConcreteSyntaxResult.fieldAccess(ConcreteSyntaxResult.java:84)
	at org.rascalmpl.semantics.dynamic.Expression$FieldAccess.interpret(Expression.java:869)
	at org.rascalmpl.semantics.dynamic.Expression$FieldAccess.interpret(Expression.java:866)
	at org.rascalmpl.semantics.dynamic.Statement$Expression.interpret(Statement.java:365)
	at org.rascalmpl.interpreter.StringTemplateConverter$Visitor$IndentingAppend.interpret(StringTemplateConverter.java:108)
	at org.rascalmpl.semantics.dynamic.Statement$NonEmptyBlock.interpret(Statement.java:759)
	at org.rascalmpl.semantics.dynamic.Statement$For.interpret(Statement.java:468)
	at org.rascalmpl.semantics.dynamic.Literal$String.interpret(Literal.java:237)
	at org.rascalmpl.semantics.dynamic.Expression$Literal.interpret(Expression.java:1596)
	at org.rascalmpl.semantics.dynamic.Expression$CallOrTree.interpret(Expression.java:502)
	at org.rascalmpl.semantics.dynamic.Expression$List.interpret(Expression.java:1521)
	at org.rascalmpl.semantics.dynamic.Statement$Expression.interpret(Statement.java:365)
	at org.rascalmpl.semantics.dynamic.Statement$Assignment.interpret(Statement.java:205)
	at org.rascalmpl.interpreter.utils.Cases.matchAndEval(Cases.java:443)
	at org.rascalmpl.interpreter.utils.Cases$DefaultBlock.matchAndEval(Cases.java:271)
	at org.rascalmpl.interpreter.TraversalEvaluator.applyCases(TraversalEvaluator.java:645)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseTop(TraversalEvaluator.java:669)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:140)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseListOnce(TraversalEvaluator.java:510)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:167)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseADTOnce(TraversalEvaluator.java:353)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:163)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseListOnce(TraversalEvaluator.java:510)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:167)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseADTOnce(TraversalEvaluator.java:353)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:163)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseListOnce(TraversalEvaluator.java:510)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:167)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseADTOnce(TraversalEvaluator.java:353)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:163)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseListOnce(TraversalEvaluator.java:510)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:167)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseADTOnce(TraversalEvaluator.java:353)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:163)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseListOnce(TraversalEvaluator.java:510)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:167)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseADTOnce(TraversalEvaluator.java:353)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverseOnce(TraversalEvaluator.java:163)
	at org.rascalmpl.interpreter.TraversalEvaluator.traverse(TraversalEvaluator.java:122)
	at org.rascalmpl.semantics.dynamic.Visit$GivenStrategy.interpret(Visit.java:132)
	at org.rascalmpl.semantics.dynamic.Statement$Visit.interpret(Statement.java:1022)
	at org.rascalmpl.interpreter.result.RascalFunction.runBody(RascalFunction.java:384)
	at org.rascalmpl.interpreter.result.RascalFunction.call(RascalFunction.java:325)
	at org.rascalmpl.interpreter.result.AbstractFunction.call(AbstractFunction.java:198)
	at org.rascalmpl.interpreter.Evaluator.call(Evaluator.java:769)
	at org.rascalmpl.interpreter.Evaluator.call(Evaluator.java:752)
	at org.rascalmpl.interpreter.Evaluator.call(Evaluator.java:558)
	at org.rascalmpl.vscode.lsp.rascal.RascalLanguageServices.lambda$getDocumentSymbols$10(RascalLanguageServices.java:203)
	at org.rascalmpl.vscode.lsp.util.EvaluatorUtil.lambda$runEvaluator$0(EvaluatorUtil.java:96)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:478)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@sungshik sungshik added the bug Something isn't working label Jan 18, 2025
@jurgenvinju
Copy link
Member

The second example makes the top-level function decapitation ambiguous. So the amb node is where the pattern for function declaration matches. Next thing the signature field is projected which doesn't exist on the amb node.

The first example has the ambiguity nested deeper, where it can do less harm.

Best solution would be the start the visit with a generic amb node case: case amb(set[Tree] alts) and either ignore it altogether, or pick one alternative to continue, or put an ambiguous DocumentSymbol in the hierarchie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants