Skip to content

Commit db92573

Browse files
authored
Giving Perm-typed expressions higher priority so that Perm is always the default for anything ambiguous (#855)
1 parent e8521cb commit db92573

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

Diff for: src/main/scala/viper/silver/parser/ParseAstKeyword.scala

+8-9
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,16 @@ trait PUnaryOp extends POperator with PSignaturesOp
345345
trait PBinaryOp extends POperator with PSignaturesOp with LeftSpace with RightSpace
346346
trait PArithOp extends PBinaryOp {
347347
override def signatures = List(
348-
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Int),
349-
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Perm))
348+
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Perm),
349+
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Int))
350350
}
351351
trait PIntOp extends PBinaryOp {
352352
override def signatures = List(Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Int))
353353
}
354354
trait PCmpOp extends PBinaryOp {
355355
override def signatures = List(
356-
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Bool),
357-
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Bool))
356+
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Bool),
357+
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Bool))
358358
}
359359
trait PLogicalOp extends PBinaryOp {
360360
override def signatures = List(Map(POpApp.pArgS(0) -> Bool, POpApp.pArgS(1) -> Bool, POpApp.pResS -> Bool))
@@ -409,11 +409,10 @@ object PSymOp {
409409
}
410410
case object Div extends PSym("/") with PSymbolOp with PBinaryOp {
411411
override def signatures = List(
412-
// The following two are not necessary if `Int` is a subtype of `Perm`
413-
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Perm),
412+
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Perm),
414413
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Int, POpApp.pResS -> Perm),
414+
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Perm),
415415
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Int),
416-
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Perm),
417416
)
418417
}
419418
case object ArithDiv extends PSym("\\") with PSymbolOp with PBinaryOp with PIntOp
@@ -428,8 +427,8 @@ object PSymOp {
428427

429428
case object Neg extends PSym("-") with PSymbolOp with PUnaryOp {
430429
override def signatures = List(
431-
Map(POpApp.pArgS(0) -> Int, POpApp.pResS -> Int),
432-
Map(POpApp.pArgS(0) -> Perm, POpApp.pResS -> Perm))
430+
Map(POpApp.pArgS(0) -> Perm, POpApp.pResS -> Perm),
431+
Map(POpApp.pArgS(0) -> Int, POpApp.pResS -> Int))
433432
}
434433
case object Not extends PSym("!") with PSymbolOp with PUnaryOp {
435434
override def signatures = List(Map(POpApp.pArgS(0) -> Bool, POpApp.pResS -> Bool))

Diff for: src/test/resources/all/issues/silver/0745.vpr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
field f: Int
5+
6+
method doubleDiv(r: Ref)
7+
{
8+
inhale acc(r.f, 1 / 4000 / 2)
9+
var tmp: Int
10+
tmp := r.f
11+
}
12+
13+
method compare(r: Ref)
14+
{
15+
assert 0 / 1 < 1 / 2
16+
assert !(0 \ 1 < 1 \ 2)
17+
18+
assert 1 / 2 > 0 / 1
19+
assert !(1 \ 2 > 0 \ 1)
20+
21+
assert !(0 / 1 >= 1 / 2)
22+
assert (0 \ 1 >= 1 \ 2)
23+
24+
assert 0 / 1 != 1 / 2
25+
assert !(0 / 1 == 1 / 2)
26+
27+
assert 0 \ 1 == 1 \ 2
28+
assert !(0 \ 1 != 1 \ 2)
29+
}

0 commit comments

Comments
 (0)