Skip to content
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

v: forbid function parameter names, shadowing imported module names #17210

Merged
merged 100 commits into from
Feb 8, 2023

Conversation

ChAoSUnItY
Copy link
Member

@ChAoSUnItY ChAoSUnItY commented Feb 3, 2023

import arrays
import maps

// FnDecl
fn x(arrays []int) {

}

struct Foo {
}

// FnDecl with receiver
fn (arrays Foo) x() {

}

fn (arrays Foo) y(maps []int) {

}

fn (foo Foo) z(arrays []int) {
	
}

// AnonFn
fn y() {
	_ := fn (arrays []int) {}
}
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:1:8: warning: module 'arrays' is imported but never used
    1 | import arrays
      |        ~~~~~~
    2 | import maps
    3 |
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:2:8: warning: module 'maps' is imported but never used
    1 | import arrays
    2 | import maps
      |        ~~~~
    3 |
    4 | // FnDecl
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:5:5: error: duplicate of an import symbol `arrays`
    3 |
    4 | // FnDecl
    5 | fn x(arrays []int) {
      |     ~~~~~~
    6 |
    7 | }
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:13:4: error: duplicate of an import symbol `arrays`
   11 |
   12 | // FnDecl with receiver
   13 | fn (arrays Foo) x() {
      |    ~~~~~~
   14 |
   15 | }
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:17:5: error: duplicate of an import symbol `arrays`
   15 | }
   16 |
   17 | fn (arrays Foo) y(maps []int) {
      |     ~~~~~~
   18 |
   19 | }
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:21:16: error: duplicate of an import symbol `arrays`
   19 | }
   20 |
   21 | fn (foo Foo) z(arrays []int) {
      |                ~~~~~~
   22 |
   23 | }
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:23:11: error: duplicate of an import symbol `arrays`
   21 | // AnonFn
   22 | fn y() {
   23 |     _ := fn (arrays []int) {}
      |              ~~~~~~
   24 | }

Note

This is a breaking change, most modules will be affected by this change, including vinix, stdlib etc.

@ChAoSUnItY ChAoSUnItY added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Feb 3, 2023
vlib/v/checker/fn.v Outdated Show resolved Hide resolved
@ChAoSUnItY ChAoSUnItY reopened this Feb 6, 2023
@spytheman spytheman closed this Feb 6, 2023
@spytheman spytheman reopened this Feb 6, 2023
spytheman pushed a commit to vlang/ved that referenced this pull request Feb 7, 2023
spytheman added a commit to vlang/ui that referenced this pull request Feb 7, 2023
spytheman added a commit to vlang/vls that referenced this pull request Feb 8, 2023
spytheman added a commit to vlang/vsl that referenced this pull request Feb 8, 2023
spytheman added a commit to vlang/vtl that referenced this pull request Feb 8, 2023
spytheman added a commit to vlang/vtl that referenced this pull request Feb 8, 2023
ChAoSUnItY added a commit to vlang/adventofcode that referenced this pull request Feb 8, 2023
@ChAoSUnItY ChAoSUnItY marked this pull request as ready for review February 8, 2023 17:22
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@spytheman
Copy link
Member

I think, that the CI will pass now (it did in the AoC repo), and I do not want to delay merging this further, because new code is added to the other repos, and it will be better to make all use the more restrictive compiler sooner than later, since that will simplify the IdeaJ plugin as well as VLS.

@spytheman spytheman merged commit 404a9aa into vlang:master Feb 8, 2023
BMJHayward pushed a commit to BMJHayward/vsl that referenced this pull request Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forbid parameters with same name as one of the imported modules
2 participants