@@ -2,6 +2,7 @@ package compiler
2
2
3
3
import (
4
4
"fmt"
5
+ "math"
5
6
"reflect"
6
7
"regexp"
7
8
@@ -329,22 +330,49 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) {
329
330
case reflect .Int :
330
331
c .emitPush (node .Value )
331
332
case reflect .Int8 :
333
+ if node .Value > math .MaxInt8 || node .Value < math .MinInt8 {
334
+ panic (fmt .Sprintf ("constant %d overflows int8" , node .Value ))
335
+ }
332
336
c .emitPush (int8 (node .Value ))
333
337
case reflect .Int16 :
338
+ if node .Value > math .MaxInt16 || node .Value < math .MinInt16 {
339
+ panic (fmt .Sprintf ("constant %d overflows int16" , node .Value ))
340
+ }
334
341
c .emitPush (int16 (node .Value ))
335
342
case reflect .Int32 :
343
+ if node .Value > math .MaxInt32 || node .Value < math .MinInt32 {
344
+ panic (fmt .Sprintf ("constant %d overflows int32" , node .Value ))
345
+ }
336
346
c .emitPush (int32 (node .Value ))
337
347
case reflect .Int64 :
348
+ if node .Value > math .MaxInt64 || node .Value < math .MinInt64 {
349
+ panic (fmt .Sprintf ("constant %d overflows int64" , node .Value ))
350
+ }
338
351
c .emitPush (int64 (node .Value ))
339
352
case reflect .Uint :
353
+ if node .Value < 0 {
354
+ panic (fmt .Sprintf ("constant %d overflows uint" , node .Value ))
355
+ }
340
356
c .emitPush (uint (node .Value ))
341
357
case reflect .Uint8 :
358
+ if node .Value > math .MaxUint8 || node .Value < 0 {
359
+ panic (fmt .Sprintf ("constant %d overflows uint8" , node .Value ))
360
+ }
342
361
c .emitPush (uint8 (node .Value ))
343
362
case reflect .Uint16 :
363
+ if node .Value > math .MaxUint16 || node .Value < 0 {
364
+ panic (fmt .Sprintf ("constant %d overflows uint16" , node .Value ))
365
+ }
344
366
c .emitPush (uint16 (node .Value ))
345
367
case reflect .Uint32 :
368
+ if node .Value > math .MaxUint32 || node .Value < 0 {
369
+ panic (fmt .Sprintf ("constant %d overflows uint32" , node .Value ))
370
+ }
346
371
c .emitPush (uint32 (node .Value ))
347
372
case reflect .Uint64 :
373
+ if node .Value < 0 {
374
+ panic (fmt .Sprintf ("constant %d overflows uint64" , node .Value ))
375
+ }
348
376
c .emitPush (uint64 (node .Value ))
349
377
default :
350
378
c .emitPush (node .Value )
0 commit comments