1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: disable overriding and importing of builtin sym types (#16452)

This commit is contained in:
Swastik Baranwal 2022-11-17 12:40:03 +05:30 committed by GitHub
parent cb9e945aa0
commit 360457e021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -2132,6 +2132,9 @@ fn (mut c Checker) import_stmt(node ast.Import) {
c.error('module `${node.mod}` has no type `${sym.name}`', sym.pos)
continue
}
if sym.name in ast.builtin_type_names {
c.error('cannot import or override builtin type', sym.pos)
}
if func := c.table.find_fn(name) {
if !func.is_pub {
c.error('module `${node.mod}` function `${sym.name}()` is private', sym.pos)

View File

@ -0,0 +1,11 @@
vlib/v/checker/tests/import_sym_builtin_override_err.vv:1:15: error: cannot import or override builtin type
1 | import rand { f64 }
| ~~~
2 |
3 | type Dot = [3]f64
vlib/v/checker/tests/import_sym_builtin_override_err.vv:3:12: error: unknown type `rand.f64`.
Did you mean `rand.PRNG`?
1 | import rand { f64 }
2 |
3 | type Dot = [3]f64
| ~~~~~~

View File

@ -0,0 +1,3 @@
import rand { f64 }
type Dot = [3]f64