mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
fix dt compiler crash
This commit is contained in:
parent
08865dbb4e
commit
e0e01f794e
@ -148,10 +148,12 @@ internal class NotExpressionAndIfComparisonExprChanger(val program: Program, val
|
||||
// not(~x) -> x!=0
|
||||
if((expr.expression as? PrefixExpression)?.operator=="~") {
|
||||
val x = (expr.expression as PrefixExpression).expression
|
||||
val dt = x.inferType(program).getOrElse { throw FatalAstException("invalid dt ${x.position}") }
|
||||
val dt = x.inferType(program).getOr(DataType.UNDEFINED)
|
||||
if(dt != DataType.UNDEFINED) {
|
||||
val notZero = BinaryExpression(x, "!=", NumericLiteral(dt, 0.0, expr.position), expr.position)
|
||||
return listOf(IAstModification.ReplaceNode(expr, notZero, parent))
|
||||
}
|
||||
}
|
||||
|
||||
// not X <compare> Y -> X <invertedcompare> Y
|
||||
val subBinExpr = expr.expression as? BinaryExpression
|
||||
|
@ -58,8 +58,8 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
||||
return listOf(IAstModification.ReplaceNode(typecast, typecast.expression, parent))
|
||||
|
||||
if(parent is Assignment) {
|
||||
val targetDt = parent.target.inferType(program).getOrElse { throw FatalAstException("invalid dt ${parent.target.position}") }
|
||||
if(sourceDt istype targetDt) {
|
||||
val targetDt = parent.target.inferType(program).getOr(DataType.UNDEFINED)
|
||||
if(targetDt!=DataType.UNDEFINED && sourceDt istype targetDt) {
|
||||
// we can get rid of this typecast because the type is already the target type
|
||||
return listOf(IAstModification.ReplaceNode(typecast, typecast.expression, parent))
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package prog8tests.ast
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.comparables.shouldBeGreaterThan
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
@ -459,6 +460,23 @@ main {
|
||||
}
|
||||
|
||||
context("various") {
|
||||
test("no crash for all sorts of undefined variables in complex expression") {
|
||||
val src = """
|
||||
%import floats
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
x_position = (((floats.cos(CORNER_ANGLE + theta) * distance_to_corner) + (position_offset as float)) * 256.0) as word
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), optimize=false, src, writeAssembly=false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBeGreaterThan 1
|
||||
errors.clear()
|
||||
compileText(C64Target(), optimize=true, src, writeAssembly=false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBeGreaterThan 1
|
||||
}
|
||||
|
||||
test("symbol names in inline assembly blocks") {
|
||||
val names1 = InlineAssembly("""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user