Skip to content

parser: fix mutiple imports at one line - #24241

Merged
spytheman merged 2 commits into
vlang:masterfrom
kbkpbot:fix-vfmt-mutiple-imports-at-oneline
Apr 16, 2025
Merged

spytheman merged 2 commits into
vlang:masterfrom
kbkpbot:fix-vfmt-mutiple-imports-at-oneline

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

Fix issue #24240

@huly-for-github

Copy link
Copy Markdown

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
Copy Markdown
Collaborator

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

kbkpbot commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor Author

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
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