NewTypedUnaryExpr returns a new UnaryExpr that is well-typed.
(op UnaryOperator, expr TypedExpr, typ *types.T)
| 1237 | |
| 1238 | // NewTypedUnaryExpr returns a new UnaryExpr that is well-typed. |
| 1239 | func NewTypedUnaryExpr(op UnaryOperator, expr TypedExpr, typ *types.T) *UnaryExpr { |
| 1240 | node := &UnaryExpr{Operator: op, Expr: expr} |
| 1241 | node.typ = typ |
| 1242 | innerType := expr.ResolvedType() |
| 1243 | |
| 1244 | _ = UnaryOps[op.Symbol].ForEachUnaryOp(func(o *UnaryOp) error { |
| 1245 | if innerType.Equivalent(o.Typ) && node.typ.Equivalent(o.ReturnType) { |
| 1246 | node.op = o |
| 1247 | return iterutil.StopIteration() |
| 1248 | } |
| 1249 | return nil |
| 1250 | }) |
| 1251 | if node.op == nil { |
| 1252 | panic(errors.AssertionFailedf("invalid TypedExpr with unary op %d: %s", op.Symbol, expr)) |
| 1253 | } |
| 1254 | return node |
| 1255 | } |
| 1256 | |
| 1257 | // FuncExpr represents a function call. |
| 1258 | type FuncExpr struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…