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)
| 12828 | // change on expressions, if you attempt to set a different type than what has |
| 12829 | // previously been set (when not initially known) this will error. |
| 12830 | func (obj *ExprIf) SetType(typ *types.Type) error { |
| 12831 | if obj.typ != nil { |
| 12832 | return obj.typ.Cmp(typ) // if not set, ensure it doesn't change |
| 12833 | } |
| 12834 | obj.typ = typ // set |
| 12835 | return nil |
| 12836 | } |
| 12837 | |
| 12838 | // Type returns the type of this expression. |
| 12839 | func (obj *ExprIf) Type() (*types.Type, error) { |