(c Constant, ctx *SemaContext, desired *types.T)
| 59 | } |
| 60 | |
| 61 | func typeCheckConstant(c Constant, ctx *SemaContext, desired *types.T) (ret TypedExpr, err error) { |
| 62 | avail := c.AvailableTypes() |
| 63 | if !desired.IsAmbiguous() { |
| 64 | for _, typ := range avail { |
| 65 | if desired.Equivalent(typ) { |
| 66 | return c.ResolveAsType(ctx, desired) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // If a numeric constant will be promoted to a DECIMAL because it was out |
| 72 | // of range of an INT, but an INT is desired, throw an error here so that |
| 73 | // the error message specifically mentions the overflow. |
| 74 | if desired.Family() == types.IntFamily { |
| 75 | if n, ok := c.(*NumVal); ok { |
| 76 | _, err := n.AsInt64() |
| 77 | switch err { |
| 78 | case errConstOutOfRange64: |
| 79 | return nil, err |
| 80 | case errConstNotInt: |
| 81 | default: |
| 82 | return nil, errors.NewAssertionErrorWithWrappedErrf(err, "unexpected error") |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | natural := avail[0] |
| 88 | return c.ResolveAsType(ctx, natural) |
| 89 | } |
| 90 | |
| 91 | func naturalConstantType(c Constant) *types.T { |
| 92 | return c.AvailableTypes()[0] |
no test coverage detected
searching dependent graphs…