Odin
Odin copied to clipboard
Range being flagged as "duplicate"
Context
Using a range in a switch is being flagged as duplicate by the compiler. I found this out while trying to check some unicode codepoints.
- Arch Linux x86
- odin version dev-2024-12:7be003557 (but I've been told that it's failing even on master branch)
Failure Information (for bugs)
/home/raph/Projects/OdinKDL2/helpers.odin(28:15) Error: Duplicate case ''\uDFFF''
previous case at /home/raph/Projects/OdinKDL2/helpers.odin(28:4)
... D800'..='\uDFFF'
Steps to Reproduce
Compile the following code and it will throw an error:
package main
foo :: proc(r: rune) {
switch r {
case '\uD800'..='\uDFFF':
}
}
Looks like the runes are both being converted to 0xFFFD (erroneous rune) before being hashed in add_constant_switch_case, which would explain the duplicate case statement.
After digging through the stack trace and having a look around, I'm not sure if this is fixable as-is. Even if you take any old rune assignment, it gets parsed into GB_RUNE_INVALID by the time the program can do anything with it.
It should be possible to add a suggestion or error message on the condition of the type being a rune and the value being 0xFFFD but that still leaves open the case where someone uses some case value, expecting it to be the one they put in, and it's actually checking 0xFFFD instead.
I'm uncertain what to do with this one.
So the error is that the rune validation is making this as invalid because the range is outside the "displayable range" (surrogate unicodes). When I showed this bug to gingerbill he thought it was an off by one, someone asked if surrogate runes should be accepted and he answered:
For context I found this bug while attempting to write a parser for the KDL format which requires validating unicodes.
As far as I know U+DFF8 and 0xDFF8 are the same thing? Odin cannot enforce this at runtime anyway, I can easily do cast(rune)0xDFF8 and I can have a surrogate in runes.
@gingerBill Is your opinion still the same? should the restriction of surrogates in rune literals be lifted?