Skip to content

Commit e89b87d

Browse files
committed
fixed type switch issue
1 parent cc417a6 commit e89b87d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

compiler/statements.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,16 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
9191
switch a := s.Assign.(type) {
9292
case *ast.AssignStmt:
9393
expr = a.Rhs[0].(*ast.TypeAssertExpr).X
94-
typeSwitchVar := c.newVariable(a.Lhs[0].(*ast.Ident).Name)
95-
for _, caseClause := range s.Body.List {
96-
c.p.objectVars[c.p.Implicits[caseClause]] = typeSwitchVar
97-
}
9894
printCaseBodyPrefix = func(index int) {
9995
value := refVar
100-
if conds := s.Body.List[index].(*ast.CaseClause).List; len(conds) == 1 {
101-
t := c.p.Types[conds[0]].Type
96+
caseClause := s.Body.List[index].(*ast.CaseClause)
97+
if len(caseClause.List) == 1 {
98+
t := c.p.Types[caseClause.List[0]].Type
10299
if _, isInterface := t.Underlying().(*types.Interface); !isInterface && !types.Identical(t, types.Typ[types.UntypedNil]) {
103100
value += ".$val"
104101
}
105102
}
106-
c.Printf("%s = %s;", typeSwitchVar, value)
103+
c.Printf("%s = %s;", c.objectName(c.p.Implicits[caseClause]), value)
107104
}
108105
case *ast.ExprStmt:
109106
expr = a.X.(*ast.TypeAssertExpr).X

0 commit comments

Comments
 (0)