@@ -2,6 +2,7 @@ package compiler
22
33import (
44"fmt"
5+ "math"
56"reflect"
67"regexp"
78
@@ -329,22 +330,49 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) {
329330case reflect .Int :
330331c .emitPush (node .Value )
331332case reflect .Int8 :
333+ if node .Value > math .MaxInt8 || node .Value < math .MinInt8 {
334+ panic (fmt .Sprintf ("constant %d overflows int8" , node .Value ))
335+ }
332336c .emitPush (int8 (node .Value ))
333337case reflect .Int16 :
338+ if node .Value > math .MaxInt16 || node .Value < math .MinInt16 {
339+ panic (fmt .Sprintf ("constant %d overflows int16" , node .Value ))
340+ }
334341c .emitPush (int16 (node .Value ))
335342case reflect .Int32 :
343+ if node .Value > math .MaxInt32 || node .Value < math .MinInt32 {
344+ panic (fmt .Sprintf ("constant %d overflows int32" , node .Value ))
345+ }
336346c .emitPush (int32 (node .Value ))
337347case reflect .Int64 :
348+ if node .Value > math .MaxInt64 || node .Value < math .MinInt64 {
349+ panic (fmt .Sprintf ("constant %d overflows int64" , node .Value ))
350+ }
338351c .emitPush (int64 (node .Value ))
339352case reflect .Uint :
353+ if node .Value < 0 {
354+ panic (fmt .Sprintf ("constant %d overflows uint" , node .Value ))
355+ }
340356c .emitPush (uint (node .Value ))
341357case reflect .Uint8 :
358+ if node .Value > math .MaxUint8 || node .Value < 0 {
359+ panic (fmt .Sprintf ("constant %d overflows uint8" , node .Value ))
360+ }
342361c .emitPush (uint8 (node .Value ))
343362case reflect .Uint16 :
363+ if node .Value > math .MaxUint16 || node .Value < 0 {
364+ panic (fmt .Sprintf ("constant %d overflows uint16" , node .Value ))
365+ }
344366c .emitPush (uint16 (node .Value ))
345367case reflect .Uint32 :
368+ if node .Value > math .MaxUint32 || node .Value < 0 {
369+ panic (fmt .Sprintf ("constant %d overflows uint32" , node .Value ))
370+ }
346371c .emitPush (uint32 (node .Value ))
347372case reflect .Uint64 :
373+ if node .Value < 0 {
374+ panic (fmt .Sprintf ("constant %d overflows uint64" , node .Value ))
375+ }
348376c .emitPush (uint64 (node .Value ))
349377default :
350378c .emitPush (node .Value )
0 commit comments