ssa: fix type assertion of same type
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package ssa
|
package ssa
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go/constant"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"log"
|
"log"
|
||||||
@@ -243,6 +244,10 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr {
|
|||||||
|
|
||||||
var eq Expr
|
var eq Expr
|
||||||
var val func() Expr
|
var val func() Expr
|
||||||
|
if x.RawType() == assertedTyp.RawType() {
|
||||||
|
eq = b.Const(constant.MakeBool(true), b.Prog.Bool())
|
||||||
|
val = func() Expr { return x }
|
||||||
|
} else {
|
||||||
if rawIntf, ok := assertedTyp.raw.Type.Underlying().(*types.Interface); ok {
|
if rawIntf, ok := assertedTyp.raw.Type.Underlying().(*types.Interface); ok {
|
||||||
eq = b.InlineCall(b.Pkg.rtFunc("Implements"), tabi, tx)
|
eq = b.InlineCall(b.Pkg.rtFunc("Implements"), tabi, tx)
|
||||||
val = func() Expr { return Expr{b.unsafeInterface(rawIntf, tx, b.faceData(x.impl)), assertedTyp} }
|
val = func() Expr { return Expr{b.unsafeInterface(rawIntf, tx, b.faceData(x.impl)), assertedTyp} }
|
||||||
@@ -250,6 +255,7 @@ func (b Builder) TypeAssert(x Expr, assertedTyp Type, commaOk bool) Expr {
|
|||||||
eq = b.BinOp(token.EQL, tx, tabi)
|
eq = b.BinOp(token.EQL, tx, tabi)
|
||||||
val = func() Expr { return b.valFromData(assertedTyp, b.faceData(x.impl)) }
|
val = func() Expr { return b.valFromData(assertedTyp, b.faceData(x.impl)) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if commaOk {
|
if commaOk {
|
||||||
prog := b.Prog
|
prog := b.Prog
|
||||||
|
|||||||
Reference in New Issue
Block a user