don't complain about uninitialized str var if it's not a var

This commit is contained in:
Irmen de Jong 2021-10-24 15:13:38 +02:00
parent 2815a14bb5
commit 6b32535cb6
3 changed files with 7 additions and 3 deletions

View File

@ -627,8 +627,12 @@ internal class AstChecker(private val program: Program,
}
if(decl.datatype==DataType.STR) {
if(decl.value==null)
err("string var must be initialized with a string literal")
if(decl.value==null) {
// complain about uninitialized str, but only if it's a regular variable
val parameter = (decl.parent as? Subroutine)?.parameters?.singleOrNull{ it.name==decl.name }
if(parameter==null)
err("string var must be initialized with a string literal")
}
else if (decl.type==VarDeclType.VAR && decl.value !is StringLiteralValue)
err("string var can only be initialized with a string literal")
}

View File

@ -36,7 +36,6 @@ class TestSubroutines {
val errors = ErrorReporterForTests()
compileText(C64Target, false, text, errors, false).assertFailure("currently str type in signature is invalid") // TODO should not be invalid
assertEquals(0, errors.warnings.size)
// TODO fix extra error "string var must be initialized with a string literal"
assertTrue(errors.errors.single().startsWith("Pass-by-reference types (str, array) cannot occur as a parameter type directly."))
}

View File

@ -1,5 +1,6 @@
main {
sub start() {
str zzz
asmfunc("text")
func("text")
}