summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-binary.h2
-rw-r--r--src/wasm-s-parser.h2
-rw-r--r--src/wasm.h9
3 files changed, 9 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index c020c3efb..26673a966 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1314,7 +1314,7 @@ public:
readExpression(curr->ifTrue);
if (code == BinaryConsts::IfElse) {
readExpression(curr->ifFalse);
- curr->type = curr->ifTrue->type;
+ curr->finalize();
}
}
void visitLoop(Loop *curr) {
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index bf9cd239f..c8d4015ea 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -797,7 +797,7 @@ private:
ret->ifTrue = parseExpression(s[2]);
if (s.size() == 4) {
ret->ifFalse = parseExpression(s[3]);
- ret->type = ret->ifTrue->type == ret->ifFalse->type ? ret->ifTrue->type : none; // if not the same type, this does not return a value
+ ret->finalize();
}
return ret;
}
diff --git a/src/wasm.h b/src/wasm.h
index 52082f3a8..ca396fd24 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -432,6 +432,12 @@ public:
if (ifFalse) printFullLine(o, indent, ifFalse);
return decIndent(o, indent);
}
+
+ void finalize() {
+ if (condition) {
+ type = getReachableWasmType(ifTrue->type, ifFalse->type);
+ }
+ }
};
class Loop : public Expression {
@@ -892,8 +898,7 @@ public:
}
void finalize() {
- type = ifTrue->type;
- if (type == none) type = ifFalse->type; // ifTrue might be unreachable
+ type = getReachableWasmType(ifTrue->type, ifFalse->type);
}
};