parser: set is_public of TypeSymbol for fn type decl (#10212)
parent
7c0cd2f41d
commit
607dbd36d7
|
@ -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{
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue