Skip to content

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

Merged
spytheman merged 1 commit intovlang:masterfrom
yuyi98:improve_check_fixed_array_method_args
Oct 24, 2024
Merged

checker: improve checking parameter mismatches for fixed array builtin methods#22630
spytheman merged 1 commit intovlang:masterfrom
yuyi98:improve_check_fixed_array_method_args

Conversation

@yuyi98
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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