mirror of
https://github.com/irmen/prog8.git
synced 2024-07-13 12:29:05 +00:00
added symbol ambiguity error (variable vs block name for scoped symbols)
fixes #114
This commit is contained in:
parent
69f6afe420
commit
299419917e
@ -75,6 +75,13 @@ internal class AstChecker(private val program: Program,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(identifier.nameInSource.size>1) {
|
||||
val lookupModule = identifier.definingScope.lookup(identifier.nameInSource.take(1))
|
||||
if(lookupModule is VarDecl) {
|
||||
errors.err("ambiguous symbol name, block name expected but found variable", identifier.position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visit(unrollLoop: UnrollLoop) {
|
||||
@ -1340,9 +1347,10 @@ internal class AstChecker(private val program: Program,
|
||||
}
|
||||
}
|
||||
} else if(postIncrDecr.target.arrayindexed != null) {
|
||||
val target = postIncrDecr.target.arrayindexed?.arrayvar?.targetStatement(program)
|
||||
val indexed = postIncrDecr.target.arrayindexed!!
|
||||
val target = indexed.arrayvar.targetStatement(program)
|
||||
if(target==null) {
|
||||
errors.err("undefined symbol", postIncrDecr.position)
|
||||
errors.undefined(indexed.arrayvar.nameInSource, indexed.arrayvar.position)
|
||||
}
|
||||
else {
|
||||
val dt = (target as VarDecl).datatype
|
||||
|
@ -24,7 +24,7 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
||||
}
|
||||
|
||||
private fun nameShadowWarning(name: String, position: Position, existing: Statement) {
|
||||
errors.warn("name '$name' shadows occurrence at ${existing.position.file} line ${existing.position.line}", position)
|
||||
errors.warn("name '$name' shadows the definition at ${existing.position.file} line ${existing.position.line}", position)
|
||||
}
|
||||
|
||||
override fun visit(block: Block) {
|
||||
@ -56,11 +56,13 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
||||
nameError(decl.name, decl.position, existingInSameScope)
|
||||
|
||||
val existingOuter = decl.parent.definingScope.lookup(listOf(decl.name))
|
||||
if (existingOuter != null && existingOuter !== decl && existingOuter is VarDecl) {
|
||||
if (existingOuter.parent !== decl.parent)
|
||||
nameShadowWarning(decl.name, decl.position, existingOuter)
|
||||
else
|
||||
nameError(decl.name, decl.position, existingOuter)
|
||||
if (existingOuter != null && existingOuter !== decl) {
|
||||
if (existingOuter is VarDecl) {
|
||||
if (existingOuter.parent !== decl.parent)
|
||||
nameShadowWarning(decl.name, decl.position, existingOuter)
|
||||
else
|
||||
nameError(decl.name, decl.position, existingOuter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import io.kotest.matchers.string.shouldStartWith
|
||||
import io.kotest.matchers.types.instanceOf
|
||||
import prog8.code.ast.PtArrayIndexer
|
||||
import prog8.code.ast.PtAssignment
|
||||
import prog8.code.ast.PtBinaryExpression
|
||||
import prog8.code.ast.PtVariable
|
||||
@ -283,8 +282,28 @@ derp {
|
||||
}
|
||||
}"""
|
||||
|
||||
compileText(VMTarget(), true, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(Cx16Target(), true, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(VMTarget(), false, src, writeAssembly = true) shouldNotBe null
|
||||
compileText(Cx16Target(), false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("ambiguous symbol name variable vs block") {
|
||||
val src = """
|
||||
main {
|
||||
sub start() {
|
||||
uword module
|
||||
module++
|
||||
module.test++
|
||||
}
|
||||
}
|
||||
|
||||
module {
|
||||
ubyte @shared test
|
||||
}
|
||||
"""
|
||||
val errors=ErrorReporterForTests()
|
||||
compileText(VMTarget(), false, src, writeAssembly = false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "ambiguous symbol"
|
||||
}
|
||||
|
||||
test("prefix expressions with typecasting") {
|
||||
|
@ -2,7 +2,7 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix the 'message' github compiler error (github)
|
||||
- also change asm subroutine and variable prefixes from `p8_` to `p8s_` / `p8v_` and be done with it once and for all.
|
||||
|
||||
|
||||
- verafx vram-vram copy routine?
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
uword module ; TODO shadow warning
|
||||
uword module
|
||||
module++
|
||||
module.test++ ; TODO compiler error
|
||||
module.test++
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user