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

checker: improve checking parameter mismatches for fixed array builtin methods #22630

Merged

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 23, 2024

This PR improve checking parameter mismatches for fixed array builtin methods.

fn main() {
	arr := [1, 2, 3]!

	_ := arr.index()
	_ := arr.index('hello')
	_ := arr.contains()
	_ := arr.contains('hello')
	_ := arr.any()
	_ := arr.any(22)
	_ := arr.all()
	_ := arr.all('hello')
}

PS D:\Test\v\tt1> v run .
tt1.v:4:11: error: `.index()` expected 1 argument, but got 0
    2 |     arr := [1, 2, 3]!
    3 | 
    4 |     _ := arr.index()
      |              ~~~~~~~
    5 |     _ := arr.index('hello')
    6 |     _ := arr.contains()
tt1.v:5:17: error: cannot use `string` as `int` in argument 1 to `.index()`
    3 | 
    4 |     _ := arr.index()
    5 |     _ := arr.index('hello')
      |                    ~~~~~~~
    6 |     _ := arr.contains()
    7 |     _ := arr.contains('hello')
tt1.v:6:11: error: `.contains()` expected 1 argument, but got 0
    4 |     _ := arr.index()
    5 |     _ := arr.index('hello')
    6 |     _ := arr.contains()
      |              ~~~~~~~~~~
    7 |     _ := arr.contains('hello')
    8 |     _ := arr.any()
tt1.v:7:20: error: cannot use `string` as `int` in argument 1 to `.contains()`
    5 |     _ := arr.index('hello')
    6 |     _ := arr.contains()
    7 |     _ := arr.contains('hello')
      |                       ~~~~~~~
    8 |     _ := arr.any()
    9 |     _ := arr.any(22)
tt1.v:8:11: error: `.any` expected 1 argument, but got 0
    6 |     _ := arr.contains()
    7 |     _ := arr.contains('hello')
    8 |     _ := arr.any()
      |              ~~~~~
    9 |     _ := arr.any(22)
   10 |     _ := arr.all()
tt1.v:10:11: error: `.all` expected 1 argument, but got 0
    8 |     _ := arr.any()
    9 |     _ := arr.any(22)
   10 |     _ := arr.all()
      |              ~~~~~
   11 |     _ := arr.all('hello')
   12 | }
tt1.v:11:15: error: type mismatch, should use e.g. `all(it > 2)`
    9 |     _ := arr.any(22)
   10 |     _ := arr.all()
   11 |     _ := arr.all('hello')
      |                  ~~~~~~~
   12 | }

Huly®: V_0.6-21079

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.

Excellent work.

@spytheman spytheman merged commit 42cc345 into vlang:master Oct 24, 2024
78 checks passed
@yuyi98 yuyi98 deleted the improve_check_fixed_array_method_args branch October 24, 2024 07:55
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.

2 participants