Skip to content

Commit

Permalink
Improve duplicate identifier error
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAlaif committed Jul 19, 2023
1 parent c2c1b11 commit 29e25ab
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/viper/silver/parser/Resolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -876,20 +876,21 @@ case class NameAnalyser() {
namesInScope ++= getCurrentMap.map(_._1)
n match {
case d: PDeclaration =>
getMap(d).get(d.idndef.name) match {
val map = getMap(d)
map.get(d.idndef.name) match {
case Some(m: PMember) if d eq m =>
// We re-encountered a member we already looked at in the previous run.
// This is expected, nothing to do.
case Some(e: PDeclaration) =>
messages ++= FastMessaging.message(e.idndef, "Duplicate identifier `" + e.idndef.name + "' at " + e.idndef.pos._1 + " and at " + d.idndef.pos._1)
messages ++= FastMessaging.message(d.idndef, "Duplicate identifier `" + e.idndef.name + "' at " + e.idndef.pos._1 + " and at " + d.idndef.pos._1)
case None =>
globalDeclarationMap.get(d.idndef.name) match {
case Some(e: PDeclaration) =>
if (!(d.parent.isDefined && d.parent.get.isInstanceOf[PDomainFunction]))
messages ++= FastMessaging.message(e, "Identifier shadowing `" + e.idndef.name + "' at " + e.idndef.pos._1 + " and at " + d.idndef.pos._1)
messages ++= FastMessaging.message(d.idndef, "Identifier shadowing `" + e.idndef.name + "' at " + e.idndef.pos._1 + " and at " + d.idndef.pos._1)
case None =>
getMap(d).put(d.idndef.name, d)
}
map.put(d.idndef.name, d)
}
case i@PIdnUse(name) =>
// look up in both maps (if we are not in a method currently, we look in the same map twice, but that is ok)
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/adt/declarations_2.vpr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
adt SimpleList {
SimpleNil()
//:: ExpectedOutput(typechecker.error)
SimpleCons(value: Int, tail: SimpleList)
//:: ExpectedOutput(typechecker.error)
SimpleCons(value: Int, tail: SimpleList)
}

adt List[T] {
Nil()
//:: ExpectedOutput(typechecker.error)
Cons(value: T, tail: List[T])
//:: ExpectedOutput(typechecker.error)
Cons(value: T, tail: List[T])
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/adt/declarations_5.vpr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
adt List[T] {
Nil()
//:: ExpectedOutput(typechecker.error)
Cons(value: T, tail: List[T])
}

//:: ExpectedOutput(typechecker.error)
field value: Int


3 changes: 2 additions & 1 deletion src/test/resources/all/basic/let_consistency_resolver.vpr
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ method test02() {
assert (let y == (0) in true) && y == 0
}

//:: ExpectedOutput(typechecker.error)
method test03(y: Int) {
//:: ExpectedOutput(typechecker.error)
assert let y == (0) in true
}

//:: ExpectedOutput(typechecker.error)
method test03() {
//:: ExpectedOutput(typechecker.error)
assert let y == (0) in let y == (true) in true
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/all/issues/silver/0027.vpr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

//:: ExpectedOutput(typechecker.error)
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

field f: Int

//:: ExpectedOutput(typechecker.error)
function f(): Bool { true }

method m(x: Ref)
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/all/issues/silver/0048.vpr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

//:: ExpectedOutput(typechecker.error)
method Bug() {}
method Bug() {}
//:: ExpectedOutput(typechecker.error)
method Bug() {}
9 changes: 5 additions & 4 deletions src/test/resources/all/issues/silver/0050.vpr
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

field f: Int
//:: ExpectedOutput(typechecker.error)
field x: Int

//:: ExpectedOutput(typechecker.error)
method test1(x: Ref)
requires acc(x.x) // error: expected field
{}

//:: ExpectedOutput(typechecker.error)
method test2(x: Ref)
requires acc(x.f) // no error
{}
2 changes: 1 addition & 1 deletion src/test/resources/all/issues/silver/0473.vpr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ domain Test[T] {
}

domain DuplicateTest[T] {
//:: ExpectedOutput(consistency.error)
//:: ExpectedOutput(typechecker.error)
function add_wrong(left: T, left: T): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ method test02() {
assert (let y == (0) in true) && y == 0
}

//:: ExpectedOutput(typechecker.error)
method test03(y: Int) {
//:: ExpectedOutput(typechecker.error)
assert let y == (0) in true
}

//:: ExpectedOutput(typechecker.error)
method test03() {
//:: ExpectedOutput(typechecker.error)
assert let y == (0) in let y == (true) in true
Expand Down

0 comments on commit 29e25ab

Please sign in to comment.