feat: add type assertion expression type checking

This adds type checking to TypeAssertExpr. In order to allow for this, method types now have a receiver type in both reflect and native cases.
This commit is contained in:
Nicholas Wiersma
2020-08-20 17:06:05 +02:00
committed by GitHub
parent 3faa47c61e
commit 3640f2f820
5 changed files with 157 additions and 34 deletions

View File

@@ -152,7 +152,7 @@ func typeAssertStatus(n *node) {
value1(f).SetBool(ok)
return next
}
case c0.typ.cat == valueT:
case c0.typ.cat == valueT || c0.typ.cat == errorT:
n.exec = func(f *frame) bltn {
v := value(f)
ok := v.IsValid() && canAssertTypes(v.Elem().Type(), rtype)
@@ -205,7 +205,7 @@ func typeAssert(n *node) {
value0(f).Set(v)
return next
}
case c0.typ.cat == valueT:
case c0.typ.cat == valueT || c0.typ.cat == errorT:
n.exec = func(f *frame) bltn {
v := value(f).Elem()
typ := value0(f).Type()
@@ -272,7 +272,7 @@ func typeAssert2(n *node) {
}
return next
}
case n.child[0].typ.cat == valueT:
case n.child[0].typ.cat == valueT || n.child[0].typ.cat == errorT:
n.exec = func(f *frame) bltn {
v := value(f).Elem()
ok := v.IsValid() && canAssertTypes(v.Type(), rtype)