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

parser: set is_public when registering enum type symbols (#8875)

This commit is contained in:
zakuro 2021-02-21 19:13:52 +09:00 committed by GitHub
parent b9edc4a414
commit 7928689ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -2217,6 +2217,7 @@ $pubfn (mut e $enum_name) toggle(flag $enum_name) { unsafe{ *e = ${enum_name}
is_flag: is_flag
is_multi_allowed: is_multi_allowed
}
is_public: is_pub
})
if idx == -1 {
p.error_with_pos('cannot register enum `$name`, another type with this name exists',

View File

@ -1,6 +1,6 @@
module main
import geometry { Point, Line, point_str, module_name }
import geometry { Point, Line, Shape, point_str, module_name }
fn test_imported_symbols_types() {
// struct init
@ -24,3 +24,15 @@ fn test_imported_symbols_functions() {
fn test_imported_symbols_constants() {
assert module_name == 'geometry'
}
fn vertex_count(s Shape) int {
return match s {
.circle { 0 }
.triangle { 3 }
.rectangle { 4 }
}
}
fn test_imported_symbols_enums() {
assert vertex_count(.triangle) == 3
}

View File

@ -4,6 +4,12 @@ const(
module_name = 'geometry'
)
pub enum Shape {
circle
rectangle
triangle
}
pub struct Point {
pub mut:
x int