diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 82d9020c2..b938e2b03 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -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") } diff --git a/compiler/test/TestSubroutines.kt b/compiler/test/TestSubroutines.kt index 84fb70136..51dbec8ec 100644 --- a/compiler/test/TestSubroutines.kt +++ b/compiler/test/TestSubroutines.kt @@ -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.")) } diff --git a/examples/test.p8 b/examples/test.p8 index 731497414..13a7e3e7f 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,5 +1,6 @@ main { sub start() { + str zzz asmfunc("text") func("text") }