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

parser: set is_public of TypeSymbol for fn type decl (#10212)

This commit is contained in:
zakuro 2021-05-27 16:17:08 +09:00 committed by GitHub
parent 7c0cd2f41d
commit 607dbd36d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -2997,6 +2997,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
// function type: `type mycallback = fn(string, int)`
fn_name := p.prepend_mod(name)
fn_type := p.parse_fn_type(fn_name)
p.table.get_type_symbol(fn_type).is_public = is_pub
type_pos = type_pos.extend(p.tok.position())
comments = p.eat_comments(same_line: true)
return ast.FnTypeDecl{

View File

@ -1,6 +1,10 @@
module main
import geometry { Line, Point, Shape, module_name, point_str }
import geometry { Line, Point, PointCond, Shape, module_name, point_str }
fn point_is(p Point, cond PointCond) bool {
return cond(p)
}
fn test_imported_symbols_types() {
// struct init
@ -17,6 +21,11 @@ fn test_imported_symbols_types() {
ps: [p0, p1]
}
assert l0.ps[0].y == 20
cond := fn (p Point) bool {
return p.x == 10
}
assert point_is(p0, cond)
}
fn test_imported_symbols_functions() {

View File

@ -35,3 +35,5 @@ pub fn (a Point) str() string {
pub fn point_str(a Point) string {
return a.str()
}
pub type PointCond = fn (p Point) bool