mirror of https://github.com/tbklang/tlang.git
TypeChecker
- If we have a `LiteralValue` and a non-`LiteralValue` then coerce the `LiteralValue` towards the non`-LiteralValue` via `typeEnforce()` - This should allow the correct range checking of literal values within the range of the to-type and not require annoying explicit casts
This commit is contained in:
parent
7f902b9fcf
commit
155298e9ee
|
@ -1575,7 +1575,31 @@ public final class TypeChecker
|
|||
assert(vLhsTypeIntegral);
|
||||
Integer vRhsTypeIntegral = cast(Integer)vRhsType;
|
||||
assert(vRhsTypeIntegral);
|
||||
if(vLhsTypeIntegral.getSize() < vRhsTypeIntegral.getSize())
|
||||
|
||||
|
||||
// TODO: There is a case to be made for when the instruction
|
||||
// with the bigger size is an IntegerLiteral - in that case
|
||||
// range checking would be nice
|
||||
// We could use isCoercibe on
|
||||
if(cast(LiteralValue)vLhsInstr || cast(LiteralValue)vRhsInstr)
|
||||
{
|
||||
// Type enforce left-hand instruction to right-hand instruction
|
||||
if(cast(LiteralValue)vLhsInstr && cast(LiteralValue)vRhsInstr is null)
|
||||
{
|
||||
typeEnforce(vRhsTypeIntegral, vLhsInstr, vLhsInstr, true);
|
||||
}
|
||||
// Type enforce right-hand instruction to left-hand instruction
|
||||
else if(cast(LiteralValue)vLhsInstr is null && cast(LiteralValue)vRhsInstr)
|
||||
{
|
||||
typeEnforce(vLhsTypeIntegral, vRhsInstr, vRhsInstr, true);
|
||||
}
|
||||
// Both are literal values
|
||||
else
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
else if(vLhsTypeIntegral.getSize() < vRhsTypeIntegral.getSize())
|
||||
{
|
||||
typeEnforce(vRhsTypeIntegral, vLhsInstr, vLhsInstr, true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue