Skip to content

Commit 1cbe393

Browse files
authored
fix: Types of small integer constants should always set a current type (#2132)
1 parent 70013e9 commit 1cbe393

File tree

77 files changed

+289
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+289
-134
lines changed

src/compiler.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,14 +3392,8 @@ export class Compiler extends DiagnosticEmitter {
33923392
): ExpressionRef {
33933393
assert(element.is(CommonFlags.INLINED | CommonFlags.RESOLVED));
33943394
var type = element.type;
3395-
switch (
3396-
!(constraints & (Constraints.CONV_IMPLICIT | Constraints.CONV_EXPLICIT)) &&
3397-
type.isIntegerValue &&
3398-
contextualType.isIntegerValue &&
3399-
type.size < contextualType.size
3400-
? (this.currentType = contextualType).kind // essentially precomputes a (sign-)extension
3401-
: (this.currentType = type).kind
3402-
) {
3395+
this.currentType = type;
3396+
switch (type.kind) {
34033397
case TypeKind.I8:
34043398
case TypeKind.I16: {
34053399
let shift = type.computeSmallIntegerShift(Type.i32);

tests/compiler/binary.untouched.wat

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,12 @@
722722
local.set $11
723723
local.get $11
724724
i64.const 52
725-
i64.const 7
725+
i32.const 7
726+
i64.extend_i32_s
726727
i64.sub
727728
i64.shr_u
728-
i64.const 127
729+
i32.const 127
730+
i64.extend_i32_s
729731
i64.and
730732
i32.wrap_i64
731733
local.set $12
@@ -1048,7 +1050,8 @@
10481050
f64.add
10491051
local.set $28
10501052
local.get $14
1051-
i64.const 127
1053+
i32.const 127
1054+
i64.extend_i32_s
10521055
i64.and
10531056
i64.const 1
10541057
i64.shl
@@ -1059,7 +1062,8 @@
10591062
i64.extend_i32_u
10601063
i64.add
10611064
i64.const 52
1062-
i64.const 7
1065+
i32.const 7
1066+
i64.extend_i32_s
10631067
i64.sub
10641068
i64.shl
10651069
local.set $13
@@ -2049,7 +2053,8 @@
20492053
i64.extend_i32_u
20502054
i64.add
20512055
i64.const 52
2052-
i64.const 5
2056+
i32.const 5
2057+
i64.extend_i32_s
20532058
i64.sub
20542059
i64.shl
20552060
i64.add

tests/compiler/call-super.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,8 @@
15361536
drop
15371537
global.get $~lib/rt/itcms/total
15381538
i64.extend_i32_u
1539-
i64.const 200
1539+
i32.const 200
1540+
i64.extend_i32_u
15401541
i64.mul
15411542
i64.const 100
15421543
i64.div_u

tests/compiler/class-implements.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,8 @@
15461546
drop
15471547
global.get $~lib/rt/itcms/total
15481548
i64.extend_i32_u
1549-
i64.const 200
1549+
i32.const 200
1550+
i64.extend_i32_u
15501551
i64.mul
15511552
i64.const 100
15521553
i64.div_u

tests/compiler/class-overloading-cast.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,8 @@
15461546
drop
15471547
global.get $~lib/rt/itcms/total
15481548
i64.extend_i32_u
1549-
i64.const 200
1549+
i32.const 200
1550+
i64.extend_i32_u
15501551
i64.mul
15511552
i64.const 100
15521553
i64.div_u

tests/compiler/class-overloading.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,8 @@
15521552
drop
15531553
global.get $~lib/rt/itcms/total
15541554
i64.extend_i32_u
1555-
i64.const 200
1555+
i32.const 200
1556+
i64.extend_i32_u
15561557
i64.mul
15571558
i64.const 100
15581559
i64.div_u

tests/compiler/class.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,8 @@
16491649
drop
16501650
global.get $~lib/rt/itcms/total
16511651
i64.extend_i32_u
1652-
i64.const 200
1652+
i32.const 200
1653+
i64.extend_i32_u
16531654
i64.mul
16541655
i64.const 100
16551656
i64.div_u

tests/compiler/constructor.untouched.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,8 @@
15481548
drop
15491549
global.get $~lib/rt/itcms/total
15501550
i64.extend_i32_u
1551-
i64.const 200
1551+
i32.const 200
1552+
i64.extend_i32_u
15521553
i64.mul
15531554
i64.const 100
15541555
i64.div_u

tests/compiler/do.untouched.wat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,8 @@
19451945
drop
19461946
global.get $~lib/rt/itcms/total
19471947
i64.extend_i32_u
1948-
i64.const 200
1948+
i32.const 200
1949+
i64.extend_i32_u
19491950
i64.mul
19501951
i64.const 100
19511952
i64.div_u
@@ -2928,7 +2929,8 @@
29282929
end
29292930
global.get $~lib/rt/itcms/total
29302931
i64.extend_i32_u
2931-
i64.const 200
2932+
i32.const 200
2933+
i64.extend_i32_u
29322934
i64.mul
29332935
i64.const 100
29342936
i64.div_u

tests/compiler/empty-exportruntime.untouched.wat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,8 @@
15421542
drop
15431543
global.get $~lib/rt/itcms/total
15441544
i64.extend_i32_u
1545-
i64.const 200
1545+
i32.const 200
1546+
i64.extend_i32_u
15461547
i64.mul
15471548
i64.const 100
15481549
i64.div_u
@@ -2455,7 +2456,8 @@
24552456
end
24562457
global.get $~lib/rt/itcms/total
24572458
i64.extend_i32_u
2458-
i64.const 200
2459+
i32.const 200
2460+
i64.extend_i32_u
24592461
i64.mul
24602462
i64.const 100
24612463
i64.div_u

0 commit comments

Comments
 (0)