Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions server/src/languages/tolk/type-inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ class InferenceWalker {
case ">":
case "<=":
case ">=":
case "<=>":
case "!=":
case "==": {
const isInverted = operator === "!="
Expand Down Expand Up @@ -1647,6 +1648,24 @@ class InferenceWalker {

return new ExprFlow(outFlow, trueFlow, falseFlow)
}
case "&":
case "|": {
flow = this.inferExpression(left, flow, false).outFlow
if (!right) {
return ExprFlow.create(flow, usedAsCondition)
}

flow = this.inferExpression(right, flow, false).outFlow

const leftType = this.ctx.getType(left)
if (leftType instanceof BoolTy) {
this.ctx.setType(node, BoolTy.BOOL)
break
}

this.ctx.setType(node, IntTy.INT)
break
}
default: {
flow = this.inferExpression(left, flow, false).outFlow
if (!right) {
Expand Down Expand Up @@ -2219,11 +2238,9 @@ class InferenceWalker {
let resultType: Ty
switch (operator) {
case "!": {
let exprType = this.ctx.getType(argument) ?? BoolTy.BOOL
if (exprType instanceof BoolTy) {
exprType = exprType.negate()
}
this.ctx.setType(node, exprType)
const exprType = this.ctx.getType(argument) ?? BoolTy.BOOL
const actualExprType = exprType instanceof BoolTy ? exprType.negate() : BoolTy.BOOL
this.ctx.setType(node, actualExprType)
return new ExprFlow(afterArg.outFlow, afterArg.falseFlow, afterArg.trueFlow)
}
case "-":
Expand Down
Loading