mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
fix a compiler crash in certain vardecl initialization expressions
This commit is contained in:
parent
fde136fb7b
commit
8dfa0bc38c
@ -28,6 +28,7 @@ class VarConstantValueTypeAdjuster(private val program: Program, private val err
|
|||||||
errors.err("refused rounding of float to avoid loss of precision", decl.value!!.position)
|
errors.err("refused rounding of float to avoid loss of precision", decl.value!!.position)
|
||||||
} else {
|
} else {
|
||||||
// cast the numeric literal to the appropriate datatype of the variable
|
// cast the numeric literal to the appropriate datatype of the variable
|
||||||
|
declConstValue.linkParents(decl)
|
||||||
val cast = declConstValue.cast(decl.datatype)
|
val cast = declConstValue.cast(decl.datatype)
|
||||||
if (cast.isValid)
|
if (cast.isValid)
|
||||||
return listOf(IAstModification.ReplaceNode(decl.value!!, cast.valueOrZero(), decl))
|
return listOf(IAstModification.ReplaceNode(decl.value!!, cast.valueOrZero(), decl))
|
||||||
|
@ -376,6 +376,17 @@ main {
|
|||||||
&ubyte[8] array = &mappedvar
|
&ubyte[8] array = &mappedvar
|
||||||
cx16.r0 = &array
|
cx16.r0 = &array
|
||||||
}
|
}
|
||||||
|
}"""
|
||||||
|
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
|
||||||
|
}
|
||||||
|
|
||||||
|
test("sizeof number const evaluation in vardecl") {
|
||||||
|
val src="""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
uword @shared size1 = sizeof(22222)
|
||||||
|
uword @shared size2 = sizeof(2.2)
|
||||||
|
}
|
||||||
}"""
|
}"""
|
||||||
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
|
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import floats
|
|
||||||
%zeropage basicsafe
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.print("enter number: ")
|
uword size1 = sizeof(22222)
|
||||||
str buffer = "???????????????????????????"
|
txt.print_uw(size1)
|
||||||
void txt.input_chars(buffer)
|
|
||||||
float value = floats.parse_f(buffer)
|
|
||||||
txt.nl()
|
txt.nl()
|
||||||
floats.print_f(value)
|
uword size2 = sizeof(2.2)
|
||||||
|
txt.print_uw(size2)
|
||||||
|
txt.nl()
|
||||||
|
cx16.r0 = sizeof(22222)
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
|
txt.nl()
|
||||||
|
cx16.r0 = sizeof(2.2)
|
||||||
|
txt.print_uw(cx16.r0)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user