( ctx context.Context, semaCtx *SemaContext, c Constant, desired *types.T, )
| 79 | } |
| 80 | |
| 81 | func typeCheckConstant( |
| 82 | ctx context.Context, semaCtx *SemaContext, c Constant, desired *types.T, |
| 83 | ) (ret TypedExpr, err error) { |
| 84 | avail := c.AvailableTypes() |
| 85 | if !desired.IsAmbiguous() { |
| 86 | for _, typ := range avail { |
| 87 | if desired.Equivalent(typ) { |
| 88 | return c.ResolveAsType(ctx, semaCtx, desired) |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // If a numeric constant will be promoted to a DECIMAL because it was out |
| 94 | // of range of an INT, but an INT is desired, throw an error here so that |
| 95 | // the error message specifically mentions the overflow. |
| 96 | if desired.Family() == types.IntFamily { |
| 97 | if n, ok := c.(*NumVal); ok { |
| 98 | _, err := n.AsInt64() |
| 99 | switch { |
| 100 | case errors.Is(err, errConstOutOfRange64): |
| 101 | return nil, err |
| 102 | case errors.Is(err, errConstNotInt): |
| 103 | default: |
| 104 | return nil, errors.NewAssertionErrorWithWrappedErrf(err, "unexpected error") |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | natural := avail[0] |
| 110 | return c.ResolveAsType(ctx, semaCtx, natural) |
| 111 | } |
| 112 | |
| 113 | func naturalConstantType(c Constant) *types.T { |
| 114 | return c.AvailableTypes()[0] |
no test coverage detected