mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: check the redefinition of built-in IError (#13606)
This commit is contained in:
parent
4215bb125c
commit
0fb1eaef04
@ -47,6 +47,10 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||
name_pos)
|
||||
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()
|
||||
no_body := p.tok.kind != .lcbr
|
||||
if language == .v && no_body {
|
||||
@ -453,6 +457,10 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||
name_pos := p.tok.pos()
|
||||
p.check_for_impure_v(language, name_pos)
|
||||
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 := ''
|
||||
if language == .js {
|
||||
interface_name = 'JS.' + modless_name
|
||||
|
5
vlib/v/parser/tests/register_ierror_interface.out
Normal file
5
vlib/v/parser/tests/register_ierror_interface.out
Normal 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 | }
|
7
vlib/v/parser/tests/register_ierror_interface.vv
Normal file
7
vlib/v/parser/tests/register_ierror_interface.vv
Normal file
@ -0,0 +1,7 @@
|
||||
interface IError {
|
||||
foo() string
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println('Hello World')
|
||||
}
|
5
vlib/v/parser/tests/register_ierror_struct.out
Normal file
5
vlib/v/parser/tests/register_ierror_struct.out
Normal 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 | }
|
7
vlib/v/parser/tests/register_ierror_struct.vv
Normal file
7
vlib/v/parser/tests/register_ierror_struct.vv
Normal file
@ -0,0 +1,7 @@
|
||||
struct IError {
|
||||
msg string
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println('Hello World')
|
||||
}
|
Loading…
Reference in New Issue
Block a user