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: check array.delete() argument mismatch (fix #22298) #22307

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 25, 2024

This PR check array.delete() argument mismatch (fix #22298).

  • Check array.delete() argument mismatch.
  • Add test.
interface IGameObject {
mut:
	name string
}

struct GameObject implements IGameObject {
mut:
	name string
}

struct Game {
mut:
	objects []IGameObject
}

fn (mut game Game) gc() {
	for obj in game.objects {
		game.objects.delete(obj)
	}
	game.objects.clear()
}

fn main() {}

PS D:\Test\v\tt1> v run .
tt1.v:18:23: error: cannot use `IGameObject` as `int` in argument 1 to `.delete()`
   16 | fn (mut game Game) gc() {
   17 |     for obj in game.objects {
   18 |         game.objects.delete(obj)
      |                             ~~~
   19 |     }
   20 |     game.objects.clear()

@medvednikov medvednikov merged commit 1dfe004 into vlang:master Sep 25, 2024
78 checks passed
@yuyi98 yuyi98 deleted the check_array_delete_args branch September 26, 2024 00:45
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.

v compiler doesn't recognize interface type when passing to array method
2 participants