docs: interfaces: is

pull/4895/head
Alexander Medvednikov 2020-05-14 17:50:48 +02:00 committed by GitHub
parent fd0d833e33
commit ab8264f8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -1003,6 +1003,11 @@ interface Speaker {
}
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()
}
@ -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 {
.key_if { return IfExpr{} }
...
@ -1052,7 +1057,7 @@ fn (p mut Parser) expr(precedence int) ast.Expr {
fn gen(expr Expr) {
match expr {
.key_if { gen_if(it) }
IfExpr { gen_if(it) }
...
}
}