Skip to content

Commit

Permalink
fix: introduce resolver type before compiling a not eq expresssion (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 committed Mar 4, 2023
1 parent 9497c3d commit ac4f29f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 66 deletions.
13 changes: 11 additions & 2 deletions src/compiler.ts
Expand Up @@ -3967,7 +3967,16 @@ export class Compiler extends DiagnosticEmitter {
}
case Token.Exclamation_Equals_Equals:
case Token.Exclamation_Equals: {
leftExpr = this.compileExpression(left, contextualType);
let resolver = this.resolver;
let leftType = resolver.resolveExpression(left, this.currentFlow, Type.auto, ReportMode.Swallow);
if (leftType == this.options.usizeType || leftType == Type.auto || leftType == null) {
let rightType = this.resolver.resolveExpression(right, this.currentFlow, Type.auto, ReportMode.Swallow);
leftType = rightType;
}
if (leftType == null) {
leftType = Type.auto;
}
leftExpr = this.compileExpression(left, leftType);
leftType = this.currentType;

// check operator overload
Expand All @@ -3982,7 +3991,7 @@ export class Compiler extends DiagnosticEmitter {

rightExpr = this.compileExpression(right, leftType);
rightType = this.currentType;
commonType = Type.commonType(leftType, rightType, contextualType);
commonType = Type.commonType(leftType, rightType);
if (!commonType) {
this.error(
DiagnosticCode.Operator_0_cannot_be_applied_to_types_1_and_2,
Expand Down
8 changes: 4 additions & 4 deletions tests/compiler/builtins.debug.wat
Expand Up @@ -3276,11 +3276,11 @@
local.set $48
i32.const 0
local.set $49
i32.const 51
local.set $50
i32.const 52
local.set $50
i32.const 53
local.set $51
i32.const 52
i32.const 53
local.set $52
i32.const 256
local.set $63
Expand Down Expand Up @@ -3325,7 +3325,7 @@
unreachable
end
local.get $50
i32.const 51
i32.const 52
i32.eq
i32.eqz
if
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/builtins.release.wat
Expand Up @@ -778,9 +778,9 @@
i32.const 5
f64.const 0
f64.const 0
f64.const 51
f64.const 52
f64.const 52
f64.const 53
f64.const 53
call $~lib/builtins/trace
global.get $~lib/memory/__stack_pointer
local.tee $0
Expand Down
76 changes: 47 additions & 29 deletions tests/compiler/field-initialization.debug.wat
Expand Up @@ -4287,6 +4287,24 @@
call $~lib/builtins/abort
unreachable
end
i32.const 0
local.get $3
local.set $34
global.get $~lib/memory/__stack_pointer
local.get $34
i32.store $0 offset=4
local.get $34
call $field-initialization/Nullable_Init#get:a
i32.ne
i32.eqz
if
i32.const 0
i32.const 432
i32.const 33
i32.const 3
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 0
call $field-initialization/Nullable#constructor
Expand All @@ -4305,7 +4323,7 @@
if
i32.const 0
i32.const 432
i32.const 40
i32.const 41
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4328,7 +4346,7 @@
if
i32.const 0
i32.const 432
i32.const 52
i32.const 53
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4351,7 +4369,7 @@
if
i32.const 0
i32.const 432
i32.const 62
i32.const 63
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4374,7 +4392,7 @@
if
i32.const 0
i32.const 432
i32.const 73
i32.const 74
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4397,7 +4415,7 @@
if
i32.const 0
i32.const 432
i32.const 83
i32.const 84
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4420,7 +4438,7 @@
if
i32.const 0
i32.const 432
i32.const 94
i32.const 95
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4455,7 +4473,7 @@
if
i32.const 0
i32.const 432
i32.const 104
i32.const 105
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4478,7 +4496,7 @@
if
i32.const 0
i32.const 432
i32.const 114
i32.const 115
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4501,7 +4519,7 @@
if
i32.const 0
i32.const 432
i32.const 124
i32.const 125
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4524,7 +4542,7 @@
if
i32.const 0
i32.const 432
i32.const 135
i32.const 136
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4547,7 +4565,7 @@
if
i32.const 0
i32.const 432
i32.const 147
i32.const 148
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4570,7 +4588,7 @@
if
i32.const 0
i32.const 432
i32.const 153
i32.const 154
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4603,7 +4621,7 @@
if
i32.const 0
i32.const 432
i32.const 164
i32.const 165
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4626,7 +4644,7 @@
if
i32.const 0
i32.const 432
i32.const 165
i32.const 166
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4664,7 +4682,7 @@
if
i32.const 0
i32.const 432
i32.const 167
i32.const 168
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4687,7 +4705,7 @@
if
i32.const 0
i32.const 432
i32.const 168
i32.const 169
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4730,7 +4748,7 @@
if
i32.const 0
i32.const 432
i32.const 170
i32.const 171
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4758,7 +4776,7 @@
if
i32.const 0
i32.const 432
i32.const 171
i32.const 172
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4806,7 +4824,7 @@
if
i32.const 0
i32.const 432
i32.const 173
i32.const 174
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4834,7 +4852,7 @@
if
i32.const 0
i32.const 432
i32.const 174
i32.const 175
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4880,7 +4898,7 @@
if
i32.const 0
i32.const 432
i32.const 182
i32.const 183
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -4903,7 +4921,7 @@
if
i32.const 0
i32.const 432
i32.const 183
i32.const 184
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4931,7 +4949,7 @@
if
i32.const 0
i32.const 432
i32.const 184
i32.const 185
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -4992,7 +5010,7 @@
if
i32.const 0
i32.const 432
i32.const 186
i32.const 187
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -5020,7 +5038,7 @@
if
i32.const 0
i32.const 432
i32.const 187
i32.const 188
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -5048,7 +5066,7 @@
if
i32.const 0
i32.const 432
i32.const 188
i32.const 189
i32.const 3
call $~lib/builtins/abort
unreachable
Expand All @@ -5072,7 +5090,7 @@
if
i32.const 0
i32.const 432
i32.const 205
i32.const 206
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -5121,7 +5139,7 @@
if
i32.const 0
i32.const 432
i32.const 218
i32.const 219
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -5178,7 +5196,7 @@
if
i32.const 0
i32.const 432
i32.const 230
i32.const 231
i32.const 3
call $~lib/builtins/abort
unreachable
Expand Down

0 comments on commit ac4f29f

Please sign in to comment.