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