Skip to content

parser: fix mutiple imports at one line #24241

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

Merged
merged 2 commits into from
Apr 16, 2025

Conversation

kbkpbot
Copy link
Contributor

@kbkpbot kbkpbot commented Apr 16, 2025

Fix issue #24240

Copy link

Connected to Huly®: V_0.6-22623

@kbkpbot kbkpbot changed the title vfmt: fix mutiple imports at one line parser: fix mutiple imports at one line Apr 16, 2025
@JalonSolov
Copy link
Contributor

I'm not sure this is the correct fix.

Because V treats whitespace as optional,

import import import os

should be treated the same as

import import
import os

The actual problem is that the import statement could be followed by other things, as in

import import as im

So what probably should be happening is that as soon as the 3rd token is not as, it should treat it as a completely separate statement, not as an error.

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Apr 16, 2025

I do some tests, seems work fine.

import math import import as im import os import kitty as k import ss

after v fmt

import math
import import as im
import os
import kitty as k
import ss

some error cases:

import import as
$ v fmt ff.v
ff.v:2:1: error: unexpected eof, expecting name
    1 | import import as

Internal vfmt error while formatting file: ff.v.
import import import
$ v fmt ff.v
ff.v:2:1: error: unexpected eof, expecting name
    1 | import import import

Internal vfmt error while formatting file: ff.v.
import import import as td
$ v fmt ff.v
ff.v:1:25: error: cannot import multiple modules at a time
    1 | import import import as td
      |                         ~~

Internal vfmt error while formatting file: ff.v.

@spytheman spytheman merged commit 422b89c into vlang:master Apr 16, 2025
74 checks passed
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