fixed crash when trying to assign a string literal to an array element in a string-array

This commit is contained in:
Irmen de Jong 2020-12-08 22:27:42 +01:00
parent ac94236614
commit cba502e87a
3 changed files with 23 additions and 5 deletions

View File

@ -384,7 +384,7 @@ internal class AstChecker(private val program: Program,
if(valueDt.isKnown && !(valueDt isAssignableTo targetDt)) {
if(targetDt.typeOrElse(DataType.STRUCT) in IterableDatatypes)
errors.err("cannot assign value to string or array", assignment.value.position)
else
else if(!(valueDt.istype(DataType.STR) && targetDt.istype(DataType.UWORD)))
errors.err("value's type doesn't match target", assignment.value.position)
}

View File

@ -725,10 +725,11 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
""")
}
TargetStorageKind.MEMORY -> {
throw AssemblyError("no asm gen for assign address $sourceName to memory word $target")
throw AssemblyError("can't store word into memory byte")
}
TargetStorageKind.ARRAY -> {
throw AssemblyError("no asm gen for assign address $sourceName to array ${target.asmVarname}")
asmgen.out(" lda #<$sourceName | ldy #>$sourceName")
assignRegisterpairWord(target, RegisterOrPair.AY)
}
TargetStorageKind.REGISTER -> {
when(target.register!!) {

View File

@ -18,8 +18,25 @@ errors {
; char = c64.CHRIN() ; TODO fix undefined symbol error, should refer to 'char' above in the subroutine's scope
; } until char==0
; TODO fix compiler crash:
; str[max_files] names
str[4] names1 = ["one", "two", "three", "four"]
str[4] names2
names2[0] = "four"
names2[1] = "three"
names2[2] = "two"
names2[3] = "one"
uword xx
for xx in names1 {
txt.print(xx)
txt.chrout(',')
}
txt.chrout('\n')
for xx in names2 {
txt.print(xx)
txt.chrout(',')
}
txt.chrout('\n')
}
}