Skip to content

Commit

Permalink
TypeChecker
Browse files Browse the repository at this point in the history
- Do allow `SymbolType.EQUALS` with two pointer operands
- Removed false assertion in exhaustive case
- If thebinary operator is `SymbolType.EQUALS` then set `chosenType` to `ubyte`
  • Loading branch information
deavmi committed May 19, 2024
1 parent 52ff503 commit 5026a05
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions source/tlang/compiler/typecheck/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -1821,19 +1821,23 @@ public final class TypeChecker
}
}
}
// If both left and right operands are pointers
else if(isPointerType(vLhsType) && isPointerType(vRhsType)) // <a> is Pointer, <b> is Pointer
/**
* If both left and right operands are pointers
* and the operator is not equality
*
* `<a> is Pointer, <b> is Pointer`
*/
else if(binOperator != SymbolType.EQUALS && isPointerType(vLhsType) && isPointerType(vRhsType))
{
expect("Both left hand side and right hand side cannot be pointers in any arithmetic operation");
expect("Both left hand side and right hand side cannot be pointers in any arithmetic operation, except equality");
}
else
{
// See issue #141: Binary Operators support for non-Integer types (https://deavmi.assigned.network/git/tlang/tlang/issues/141)
ERROR("FIXME: We need to add support for this, class equality, and others like floats");
assert(false);
}


/**
* Refresh types as instructions may have changed in
* the above enforcement call
Expand All @@ -1854,8 +1858,17 @@ public final class TypeChecker
Type chosenType;
if(isSameType(vLhsType, vRhsType))
{
/* Left type + Right type = left/right type (just use left - it doesn't matter) */
chosenType = vLhsType;
/* If equality then result is `ubyte` */
if(binOperator == SymbolType.EQUALS)
{
chosenType = getType(this.program, "ubyte");
}
/* Other cases */
else
{
/* Left type + Right type = left/right type (just use left - it doesn't matter) */
chosenType = vLhsType;
}
}
else
{
Expand Down

0 comments on commit 5026a05

Please sign in to comment.