parser: check the redefinition of built-in IError (#13606)

pull/13609/head
yuyi 2022-02-26 15:52:40 +08:00 committed by GitHub
parent 4215bb125c
commit 0fb1eaef04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 0 deletions

View File

@ -47,6 +47,10 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
name_pos) name_pos)
return ast.StructDecl{} return ast.StructDecl{}
} }
if name == 'IError' && p.mod != 'builtin' {
p.error_with_pos('cannot register struct `IError`, it is builtin interface type',
name_pos)
}
generic_types, _ := p.parse_generic_types() generic_types, _ := p.parse_generic_types()
no_body := p.tok.kind != .lcbr no_body := p.tok.kind != .lcbr
if language == .v && no_body { if language == .v && no_body {
@ -453,6 +457,10 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
name_pos := p.tok.pos() name_pos := p.tok.pos()
p.check_for_impure_v(language, name_pos) p.check_for_impure_v(language, name_pos)
modless_name := p.check_name() modless_name := p.check_name()
if modless_name == 'IError' && p.mod != 'builtin' {
p.error_with_pos('cannot register interface `IError`, it is builtin interface type',
name_pos)
}
mut interface_name := '' mut interface_name := ''
if language == .js { if language == .js {
interface_name = 'JS.' + modless_name interface_name = 'JS.' + modless_name

View File

@ -0,0 +1,5 @@
vlib/v/parser/tests/register_ierror_interface.vv:1:11: error: cannot register interface `IError`, it is builtin interface type
1 | interface IError {
| ~~~~~~
2 | foo() string
3 | }

View File

@ -0,0 +1,7 @@
interface IError {
foo() string
}
fn main() {
println('Hello World')
}

View File

@ -0,0 +1,5 @@
vlib/v/parser/tests/register_ierror_struct.vv:1:8: error: cannot register struct `IError`, it is builtin interface type
1 | struct IError {
| ~~~~~~
2 | msg string
3 | }

View File

@ -0,0 +1,7 @@
struct IError {
msg string
}
fn main() {
println('Hello World')
}