mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 08:29:25 +00:00
don't complain about uninitialized str var if it's not a var
This commit is contained in:
parent
2815a14bb5
commit
6b32535cb6
@ -627,8 +627,12 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(decl.datatype==DataType.STR) {
|
if(decl.datatype==DataType.STR) {
|
||||||
if(decl.value==null)
|
if(decl.value==null) {
|
||||||
err("string var must be initialized with a string literal")
|
// 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)
|
else if (decl.type==VarDeclType.VAR && decl.value !is StringLiteralValue)
|
||||||
err("string var can only be initialized with a string literal")
|
err("string var can only be initialized with a string literal")
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ class TestSubroutines {
|
|||||||
val errors = ErrorReporterForTests()
|
val errors = ErrorReporterForTests()
|
||||||
compileText(C64Target, false, text, errors, false).assertFailure("currently str type in signature is invalid") // TODO should not be invalid
|
compileText(C64Target, false, text, errors, false).assertFailure("currently str type in signature is invalid") // TODO should not be invalid
|
||||||
assertEquals(0, errors.warnings.size)
|
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."))
|
assertTrue(errors.errors.single().startsWith("Pass-by-reference types (str, array) cannot occur as a parameter type directly."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
|
str zzz
|
||||||
asmfunc("text")
|
asmfunc("text")
|
||||||
func("text")
|
func("text")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user