Skip to content

Commit 0fb1eae

Browse files
authored
parser: check the redefinition of built-in IError (#13606)
1 parent 4215bb1 commit 0fb1eae

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

vlib/v/parser/struct.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
4747
name_pos)
4848
return ast.StructDecl{}
4949
}
50+
if name == 'IError' && p.mod != 'builtin' {
51+
p.error_with_pos('cannot register struct `IError`, it is builtin interface type',
52+
name_pos)
53+
}
5054
generic_types, _ := p.parse_generic_types()
5155
no_body := p.tok.kind != .lcbr
5256
if language == .v && no_body {
@@ -453,6 +457,10 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
453457
name_pos := p.tok.pos()
454458
p.check_for_impure_v(language, name_pos)
455459
modless_name := p.check_name()
460+
if modless_name == 'IError' && p.mod != 'builtin' {
461+
p.error_with_pos('cannot register interface `IError`, it is builtin interface type',
462+
name_pos)
463+
}
456464
mut interface_name := ''
457465
if language == .js {
458466
interface_name = 'JS.' + modless_name
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/parser/tests/register_ierror_interface.vv:1:11: error: cannot register interface `IError`, it is builtin interface type
2+
1 | interface IError {
3+
| ~~~~~~
4+
2 | foo() string
5+
3 | }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface IError {
2+
foo() string
3+
}
4+
5+
fn main() {
6+
println('Hello World')
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/parser/tests/register_ierror_struct.vv:1:8: error: cannot register struct `IError`, it is builtin interface type
2+
1 | struct IError {
3+
| ~~~~~~
4+
2 | msg string
5+
3 | }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct IError {
2+
msg string
3+
}
4+
5+
fn main() {
6+
println('Hello World')
7+
}

0 commit comments

Comments
 (0)