@@ -34,10 +34,7 @@ func roundFloat(v constant.Value, sz int64) constant.Value {
34
34
// truncate float literal fv to 32-bit or 64-bit precision
35
35
// according to type; return truncated value.
36
36
func truncfltlit (v constant.Value , t * types.Type ) constant.Value {
37
- if t .IsUntyped () || overflow (v , t ) {
38
- // If there was overflow, simply continuing would set the
39
- // value to Inf which in turn would lead to spurious follow-on
40
- // errors. Avoid this by returning the existing value.
37
+ if t .IsUntyped () {
41
38
return v
42
39
}
43
40
@@ -48,10 +45,7 @@ func truncfltlit(v constant.Value, t *types.Type) constant.Value {
48
45
// precision, according to type; return truncated value. In case of
49
46
// overflow, calls Errorf but does not truncate the input value.
50
47
func trunccmplxlit (v constant.Value , t * types.Type ) constant.Value {
51
- if t .IsUntyped () || overflow (v , t ) {
52
- // If there was overflow, simply continuing would set the
53
- // value to Inf which in turn would lead to spurious follow-on
54
- // errors. Avoid this by returning the existing value.
48
+ if t .IsUntyped () {
55
49
return v
56
50
}
57
51
@@ -251,7 +245,6 @@ func convertVal(v constant.Value, t *types.Type, explicit bool) constant.Value {
251
245
switch {
252
246
case t .IsInteger ():
253
247
v = toint (v )
254
- overflow (v , t )
255
248
return v
256
249
case t .IsFloat ():
257
250
v = toflt (v )
@@ -273,9 +266,6 @@ func tocplx(v constant.Value) constant.Value {
273
266
274
267
func toflt (v constant.Value ) constant.Value {
275
268
if v .Kind () == constant .Complex {
276
- if constant .Sign (constant .Imag (v )) != 0 {
277
- base .Errorf ("constant %v truncated to real" , v )
278
- }
279
269
v = constant .Real (v )
280
270
}
281
271
@@ -284,9 +274,6 @@ func toflt(v constant.Value) constant.Value {
284
274
285
275
func toint (v constant.Value ) constant.Value {
286
276
if v .Kind () == constant .Complex {
287
- if constant .Sign (constant .Imag (v )) != 0 {
288
- base .Errorf ("constant %v truncated to integer" , v )
289
- }
290
277
v = constant .Real (v )
291
278
}
292
279
@@ -321,25 +308,6 @@ func toint(v constant.Value) constant.Value {
321
308
return constant .MakeInt64 (1 )
322
309
}
323
310
324
- // overflow reports whether constant value v is too large
325
- // to represent with type t, and emits an error message if so.
326
- func overflow (v constant.Value , t * types.Type ) bool {
327
- // v has already been converted
328
- // to appropriate form for t.
329
- if t .IsUntyped () {
330
- return false
331
- }
332
- if v .Kind () == constant .Int && constant .BitLen (v ) > ir .ConstPrec {
333
- base .Errorf ("integer too large" )
334
- return true
335
- }
336
- if ir .ConstOverflow (v , t ) {
337
- base .Errorf ("constant %v overflows %v" , types .FmtConst (v , false ), t )
338
- return true
339
- }
340
- return false
341
- }
342
-
343
311
func tostr (v constant.Value ) constant.Value {
344
312
if v .Kind () == constant .Int {
345
313
r := unicode .ReplacementChar
0 commit comments