shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
Other
2.59k stars 201 forks source link

Error message underline position is not calculated correctly #5219

Open expipiplus1 opened 1 month ago

expipiplus1 commented 1 month ago

consider this file

// Single byte code points
/* abc */ aaa;
// Two byte code points
/* αβγ */ bbb;
// Single byte code points each followed by a two byte combining character
/* âb̃c⃗ */ ccc;
// Three byte code points of Wide characters
/* 救命!我被困在编译器工厂里了! */ ddd;

Notice how the error underlines are incorrectly positioned

+ build/Debug/bin/slangc -line-directive-mode none test.slang -stage compute
test.slang(2): error 39999: declaration does not declare anything
/* abc */ aaa;
          ^~~
test.slang(4): error 39999: declaration does not declare anything
/* αβγ */ bbb;
             ^~~
test.slang(6): error 39999: declaration does not declare anything
/* âb̃c⃗ */ ccc;
                 ^~~
test.slang(8): error 39999: declaration does not declare anything
/* 救命!我被困在编译器工厂里了! */ ddd;
                                                    ^~~

It's probably a losing battle trying to capture all the corner cases, but hooking up wcwidth and counting grapheme clusters might make the output look a little more pro in any sensible case

(also we should probably remove this outdated info from the docs haha

The identifier consistent of a single underscore (_) is reserved by the language and must not be used by programs. Otherwise, there are no fixed keywords or reserved words. Words that name a built-in language construct can also be used as user-defined identifiers and will shadow the built-in definitions in the scope of their definition.

)

bmillsNV commented 1 month ago

Leaving in backlog for now. Not critical for us to fix.

expipiplus1 commented 2 days ago

We should revisit this with slightly more urgency since https://github.com/shader-slang/slang/pull/4772 is implemented.