docs: interfaces: is
parent
fd0d833e33
commit
ab8264f8be
|
@ -1003,6 +1003,11 @@ interface Speaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn perform(s Speaker) string {
|
fn perform(s Speaker) string {
|
||||||
|
if s is Dog { // use `is` to check the underlying type of an interface
|
||||||
|
println('perform(dog)')
|
||||||
|
} else if s is Cat {
|
||||||
|
println('perform(cat)')
|
||||||
|
}
|
||||||
return s.speak()
|
return s.speak()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,7 +1047,7 @@ struct CallExpr {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) expr(precedence int) ast.Expr {
|
fn (p mut Parser) expr(precedence int) Expr {
|
||||||
match p.tok {
|
match p.tok {
|
||||||
.key_if { return IfExpr{} }
|
.key_if { return IfExpr{} }
|
||||||
...
|
...
|
||||||
|
@ -1052,7 +1057,7 @@ fn (p mut Parser) expr(precedence int) ast.Expr {
|
||||||
|
|
||||||
fn gen(expr Expr) {
|
fn gen(expr Expr) {
|
||||||
match expr {
|
match expr {
|
||||||
.key_if { gen_if(it) }
|
IfExpr { gen_if(it) }
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue