rascal

Rascal throws "Ambiguous code" error when getting type


When trying to get the type of a function taking one data parameter, I am getting an AmbiguityError.

Imagine I define the following data type:

data Foo = bar(int x);

The following expressions work fine:

#Foo
#int
#Foo(int)
#int(Foo, int)

However, the expression int(Foo) gives me the following error:

Unexpected failure during parsing of current command: 
Ambiguous code (internal error), #int(Foo)
org.rascalmpl.interpreter.asserts.Ambiguous: Ambiguous code (internal error), #int(Foo)
    at org.rascalmpl.parser.uptr.UPTRNodeFactory.buildAmbiguityNode(UPTRNodeFactory.java:76)
    at org.rascalmpl.parser.uptr.UPTRNodeFactory.createAmbiguityNode(UPTRNodeFactory.java:85)
    at org.rascalmpl.parser.uptr.UPTRNodeFactory.createAmbiguityNode(UPTRNodeFactory.java:23)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:183)
    at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.buildAlternative(SortContainerNodeFlattener.java:90)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:65)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherAlternatives(SortContainerNodeFlattener.java:53)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:166)
    at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.buildAlternative(SortContainerNodeFlattener.java:90)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:65)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:71)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherProduction(SortContainerNodeFlattener.java:71)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.gatherAlternatives(SortContainerNodeFlattener.java:53)
    at org.rascalmpl.parser.gtd.result.out.SortContainerNodeFlattener.convertToUPTR(SortContainerNodeFlattener.java:166)
    at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:63)
    at org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener.convert(DefaultNodeFlattener.java:79)
    at org.rascalmpl.parser.gtd.SGTDBF.buildResult(SGTDBF.java:1297)
    at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1236)
    at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1240)
    at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1252)
    at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1023)
    at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1013)
    at org.rascalmpl.repl.RascalInterpreterREPL.isStatementComplete(RascalInterpreterREPL.java:174)
    at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:105)
    at org.rascalmpl.shell.REPLRunner$1.handleInput(REPLRunner.java:61)
    at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:180)
    at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:347)
    at org.rascalmpl.shell.REPLRunner.run(REPLRunner.java:96)
    at org.rascalmpl.shell.RascalShell.main(RascalShell.java:69)
>>>>>>>

What is wrong with this expression? Why is it ambiguous?


Solution

  • It's ambiguous because we forgot to prioritize the # operator's function type over the expression syntax for calling function.

    You can use more brackets to get around the ambiguity.