func visitChangeType(inst *ssa.ChangeType, fr *frame) { switch vd, kind := fr.get(inst.X); kind { case Chan: fr.locals[inst] = vd // ChangeType from <-chan and chan<- ch := fr.env.chans[vd] fmt.Fprintf(os.Stderr, " & changetype from %s to %s (channel %s)\n", green(reg(inst.X)), reg(inst), ch.Name()) fmt.Fprintf(os.Stderr, " ^ origin\n") case Nothing: fmt.Fprintf(os.Stderr, " # changetype %s = %s %s\n", inst.Name(), inst.X.Name(), inst.String()) fmt.Fprintf(os.Stderr, " ^ unknown kind\n") default: fr.locals[inst] = vd fmt.Fprintf(os.Stderr, " # changetype %s = %s\n", red(inst.Name()), inst.String()) } }
func visitChangeType(instr *ssa.ChangeType, infer *TypeInfer, ctx *Context) { inst, ok := ctx.F.locals[instr.X] if !ok { infer.Logger.Fatalf("changetype: %s: %v → %v", ErrUnknownValue, instr.X, instr) return } ctx.F.locals[instr] = inst if a, ok := ctx.F.arrays[ctx.F.locals[instr.X]]; ok { ctx.F.arrays[ctx.F.locals[instr]] = a } if s, ok := ctx.F.structs[ctx.F.locals[instr.X]]; ok { ctx.F.structs[ctx.F.locals[instr]] = s } if m, ok := ctx.F.maps[ctx.F.locals[instr.X]]; ok { ctx.F.maps[ctx.F.locals[instr]] = m } infer.Logger.Print(ctx.F.Sprintf(ValSymbol+"%s = %s (type: %s ← %s)", instr.Name(), instr.X.Name(), fmtType(instr.Type()), fmtType(instr.X.Type().Underlying()))) ctx.F.revlookup[instr.Name()] = instr.X.Name() if indirect, ok := ctx.F.revlookup[instr.X.Name()]; ok { ctx.F.revlookup[instr.Name()] = indirect } return }