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

Ambiguity when combining tuple projection and string interpolation #2122

Open
sungshik opened this issue Jan 15, 2025 · 0 comments
Open

Ambiguity when combining tuple projection and string interpolation #2122

sungshik opened this issue Jan 15, 2025 · 0 comments

Comments

@sungshik
Copy link
Contributor

sungshik commented Jan 15, 2025

Describe the bug

An ambiguity may arise when tuple projection is combined with string interpolation.

To Reproduce

rascal>x = <"foo", "bar">;
tuple[str,str]: <"foo","bar">

rascal>"<x<0>>"
str: "foo"

rascal>"<x<1>>"
str: "bar"

rascal>"<x<0>><x<1>>"
Unexpected failure during parsing of current command: 
Ambiguous code (internal error), x<0>><x<1>

Expected behavior

rascal>"<x<0>><x<1>>"
str: "foobar"

I think the alternative the parser is considering is this:

"<x<0>><x<1>>"
  └─┘   └─┘    less-than:      x<0      x<1
       └───┘   unary tuple:           <(x<1)>
  └────────┘   insert-before: (x<0)>>(<(x<1)>)

This is not well-typed, but the parser doesn't mind.

Stack traces

org.rascalmpl.interpreter.asserts.Ambiguous: Ambiguous code (internal error), x<0>><x<1>
        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.gatherProduction(SortContainerNodeFlattener.java:71)
        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.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.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.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.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:1306)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1245)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1249)
        at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1261)
        at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1052)
        at org.rascalmpl.interpreter.Evaluator.parseCommand(Evaluator.java:1042)
        at org.rascalmpl.repl.RascalInterpreterREPL.isStatementComplete(RascalInterpreterREPL.java:176)
        at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:105)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.handleInput(LSPTerminalREPL.java:233)
        at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:179)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:346)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:320)
@sungshik sungshik changed the title Ambiguity when combining tuples and interpolation Ambiguity when combining tuple projection and string interpolation Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant