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

parser: check non-generic interface defining generic method (fix #20430) #20545

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jan 15, 2024

This PR check non-generic interface defining generic method (fix #20430).

  • Check non-generic interface defining generic method.
  • Add test.
module main

interface Abc {
	test[T]()
}

struct Xyz {}

fn (xyz Xyz) test[T]() {}

fn main() {
	_ := Abc(Xyz{})
}

PS D:\Test\v\tt1> v run .
tt1.v:4:6: error: non-generic interface `Abc` cannot define a generic method
    2 | 
    3 | interface Abc {
    4 |     test[T]()
      |         ^
    5 | }
    6 |

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.

@@ -1,4 +1,4 @@
interface Expr {
interface Expr<R> {
Copy link
Member

Choose a reason for hiding this comment

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

I am curious, why use interface Expr<R> {, instead of the newer interface Expr[R] { ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll cleanup them.

@spytheman spytheman merged commit 13a3a89 into vlang:master Jan 15, 2024
54 checks passed
@yuyi98 yuyi98 deleted the check_generic_interface_decl branch January 16, 2024 00:51
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.

Checker error with interface with generic method
2 participants