better error message for ambiguous multi-var initialization in vardecl

This commit is contained in:
Irmen de Jong 2024-04-08 22:36:00 +02:00
parent f88c29e083
commit 19ebc6d6b3
3 changed files with 14 additions and 5 deletions

View File

@ -74,6 +74,13 @@ internal class LiteralsToAutoVars(private val program: Program, private val erro
override fun after(decl: VarDecl, parent: Node): Iterable<IAstModification> {
if(decl.names.size>1) {
val fcallTarget = (decl.value as? IFunctionCall)?.target?.targetSubroutine(program)
if(fcallTarget!=null && fcallTarget.returntypes.size>1) {
errors.err("ambiguous multi-variable initialization. Use separate variable declaration and assignment(s) instead.", decl.value!!.position)
return noModifications
}
// note: the desugaring of a multi-variable vardecl has to be done here
// and not in CodeDesugarer, that one is too late (identifiers can't be found otherwise)
if(decl.datatype !in NumericDatatypesWithBoolean)

View File

@ -1,8 +1,6 @@
TODO
====
can we make ubyte x,y = cbm.SCREEN() work? (sugar for ubyte x,y // x,y=cbm.SCREEN() ?)
...

View File

@ -4,8 +4,12 @@
main {
sub start() {
ubyte @shared x,y,z
ubyte @shared k,l,m = 42
uword @shared r,s,t = sys.progend()
ubyte @shared x,y = multi()
}
asmsub multi() -> ubyte @A, ubyte @Y {
%asm {{
rts
}}
}
}