mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +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)
|
||||
} else {
|
||||
// cast the numeric literal to the appropriate datatype of the variable
|
||||
declConstValue.linkParents(decl)
|
||||
val cast = declConstValue.cast(decl.datatype)
|
||||
if (cast.isValid)
|
||||
return listOf(IAstModification.ReplaceNode(decl.value!!, cast.valueOrZero(), decl))
|
||||
|
@ -376,6 +376,17 @@ main {
|
||||
&ubyte[8] array = &mappedvar
|
||||
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
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
%import textio
|
||||
%import floats
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
txt.print("enter number: ")
|
||||
str buffer = "???????????????????????????"
|
||||
void txt.input_chars(buffer)
|
||||
float value = floats.parse_f(buffer)
|
||||
uword size1 = sizeof(22222)
|
||||
txt.print_uw(size1)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user