Switch structure with comma in function outputs code??
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 540
- PR merge metrics
- No merged PRs in 30d
Description
After I saw the results of this thing, I realized that nowhere in *Writing with Ink* does it suggest that Ink has support for multiple cases on a single line in a switch case structure, but the output of this is so bizzare I figured I'd write this up anyway. Also, I would expect the two cases on a single line thing to error if it's not supported. Instead, it seems like the lexer takes a holiday.
Source:
```ink
VAR A = ???
Output: {hello()}
== function hello()
{A:
- 2: ~ return "Hola"
- 1, 0: ~ return "Hello?"
}
~ return "Um, what?"
```
When `A` is set to 2, we get the expected output:
> Output: Hola
> **End of story**
But when `A` is set to *anything* else, we get this very unexpected output:
> Output: 1, 0: ~ return "Hello?"Um, what?
> **End of story**
I'm expecting A = 0 or 1 to output "Hello?", and anything else to output "Um, what?". But the story seems to be outputting the entire raw code line and concatenating that onto the default return. If the comma separated multi-case is not supported, I would have expected a compile-time error.
I don't know what the lexer is seeing in that comma separated value list to make it think the entire line after the dash is supposed to be returned, let alone concatenated raw onto the front of the return. It seems to be specifically the comma that's causing this problem, as if I put a comma after the `2`, it outputs that line instead.
If it makes any difference, I found this while using Inky's output pane, programming on a Mac.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.