Skip to content

builtin/v.util: correct error underline for unicode wide chars - #9010

Merged
medvednikov merged 3 commits into
vlang:masterfrom
zakuro9715:cjk-error-message
Feb 28, 2021
Merged

medvednikov merged 3 commits into
vlang:masterfrom
zakuro9715:cjk-error-message

Conversation

@zakuro9715

Copy link
Copy Markdown
Member

Currently wrong underline is showed for source code that includes wide character like this.

vlib/v/checker/tests/error_with_unicode.vv:5:17: error: cannot use `int literal` as `string` in argument 2 to `f1`
    3 |
    4 | fn main() {
    5 |     f1('🐀🐈', 0)
      |                    ^
    6 |     f2(0, '🐟🐧')
    7 |     mut n := 0
vlib/v/checker/tests/error_with_unicode.vv:6:8: error: cannot use `string` as `int` in argument 2 to `f2`
    4 | fn main() {
    5 |     f1('🐀🐈', 0)
    6 |     f2(0, '🐟🐧')
      |           ~~~~~~~~~~
    7 |     mut n := 0
    8 |     n = '漢字'
vlib/v/checker/tests/error_with_unicode.vv:8:6: error: cannot assign to `n`: expected `int`, not `string`
    6 |     f2(0, '🐟🐧')
    7 |     mut n := 0
    8 |     n = '漢字'
      |         ~~~~~~~~
    9 |     n = 'ひらがな'
   10 |     n = '简体字'
vlib/v/checker/tests/error_with_unicode.vv:9:6: error: cannot assign to `n`: expected `int`, not `string`
    7 |     mut n := 0
    8 |     n = '漢字'
    9 |     n = 'ひらがな'
      |         ~~~~~~~~~~~~~~
   10 |     n = '简体字'
   11 |     n = '繁體字'
vlib/v/checker/tests/error_with_unicode.vv:10:6: error: cannot assign to `n`: expected `int`, not `string`
    8 |     n = '漢字'
    9 |     n = 'ひらがな'
   10 |     n = '简体字'
      |         ~~~~~~~~~~~
   11 |     n = '繁體字'
   12 |     n = '한글'
vlib/v/checker/tests/error_with_unicode.vv:11:6: error: cannot assign to `n`: expected `int`, not `string`
    9 |     n = 'ひらがな'
   10 |     n = '简体字'
   11 |     n = '繁體字'
      |         ~~~~~~~~~~~
   12 |     n = '한글'
   13 |     n = 'Кириллица'
vlib/v/checker/tests/error_with_unicode.vv:12:6: error: cannot assign to `n`: expected `int`, not `string`
   10 |     n = '简体字'
   11 |     n = '繁體字'
   12 |     n = '한글'
      |         ~~~~~~~~
   13 |     n = 'Кириллица'
   14 | }
vlib/v/checker/tests/error_with_unicode.vv:13:6: error: cannot assign to `n`: expected `int`, not `string`
   11 |     n = '繁體字'
   12 |     n = '한글'
   13 |     n = 'Кириллица'
      |         ~~~~~~~~~~~~~~~~~~~~
   14 | }

encoding.utf8.east_asian.display_width exists. But it has big table. So I added simplified detection to utf8_str_visible_length

@zakuro9715

Copy link
Copy Markdown
Member Author

V panic: realloc(-1881639476) failed

Hmm... I have no idea why it's an error. No error occurs on my local environment.

@spytheman

Copy link
Copy Markdown
Contributor

(rebased over current master, after the optional PRs merge)

@spytheman

Copy link
Copy Markdown
Contributor

I think the problem is in the match handling.
Currently the compiler keeps a map for them (to implement the exhaustion), and that map makes it allocate too much memory.
See vlib/v/checker/checker.v:4433

@zakuro9715

Copy link
Copy Markdown
Member Author

Got it! I gained more knowledge about V internal

@medvednikov
medvednikov merged commit ce115dc into vlang:master Feb 28, 2021
@zakuro9715
zakuro9715 deleted the cjk-error-message branch March 9, 2021 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants