SetType is used to set the type of this expression once it is known. This usually happens during type unification, but it can also happen during parsing if a type is specified explicitly. Since types are static and don't change on expressions, if you attempt to set a different type than what has pre
(typ *types.Type)
| 11540 | // change on expressions, if you attempt to set a different type than what has |
| 11541 | // previously been set (when not initially known) this will error. |
| 11542 | func (obj *ExprVar) SetType(typ *types.Type) error { |
| 11543 | if obj.typ != nil { |
| 11544 | return obj.typ.Cmp(typ) // if not set, ensure it doesn't change |
| 11545 | } |
| 11546 | obj.typ = typ // set |
| 11547 | return nil |
| 11548 | } |
| 11549 | |
| 11550 | // Type returns the type of this expression. |
| 11551 | func (obj *ExprVar) Type() (*types.Type, error) { |