summaryrefslogtreecommitdiff
path: root/Test/dafny0/Trait
diff options
context:
space:
mode:
authorGravatar leino <unknown>2015-04-05 13:32:12 -0700
committerGravatar leino <unknown>2015-04-05 13:32:12 -0700
commit0aeab928abc85e646dc58c4dc4670a03a36cbc2f (patch)
treef2743fc9914ae0a5b00130776a59fb4e53dffe8e /Test/dafny0/Trait
parente9c7c508c1900e6195164d263c9249e3c7b56b51 (diff)
Fixed compilation of static members in traits
Diffstat (limited to 'Test/dafny0/Trait')
-rw-r--r--Test/dafny0/Trait/TraitCompile.dfy71
-rw-r--r--Test/dafny0/Trait/TraitCompile.dfy.expect18
2 files changed, 89 insertions, 0 deletions
diff --git a/Test/dafny0/Trait/TraitCompile.dfy b/Test/dafny0/Trait/TraitCompile.dfy
new file mode 100644
index 00000000..cc667a9a
--- /dev/null
+++ b/Test/dafny0/Trait/TraitCompile.dfy
@@ -0,0 +1,71 @@
+// RUN: %dafny /compile:3 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+trait TT
+{
+ function method Plus(x:int, y:int) : int
+ requires x > y
+ {
+ x + y
+ }
+ function method Times(x:int, y:int) : int
+ requires x > y
+ static function method StaticMinus(x:int, y:int) : int
+ requires x > y
+ {
+ x - y
+ }
+
+ method Double(x: int)
+ {
+ print "d=", x+x, "\n";
+ }
+ method AddFive(x: int)
+ static method StaticTriple(x: int)
+ {
+ print "t=", 3*x, "\n";
+ }
+}
+
+class CC extends TT
+{
+ function method Times(x:int, y:int) : int
+ requires x>y
+ {
+ x * y
+ }
+ method AddFive(x: int)
+ {
+ print "a5=", x+5, "\n";
+ }
+}
+
+method Client(t: TT)
+ requires t != null
+{
+ var x := t.Plus(10, 2);
+ print "x=", x, "\n";
+ t.Double(400);
+ t.AddFive(402);
+ t.StaticTriple(404);
+}
+
+method Main()
+{
+ var c := new CC;
+ var y := c.Plus(100, 20);
+ print "y=", y, "\n";
+ Client(c);
+ var z := TT.StaticMinus(50, 20);
+ print "z=", z, "\n";
+ var z' := CC.StaticMinus(50, 20);
+ print "z'=", z', "\n";
+ var w := c.StaticMinus(50, 20);
+ print "w=", w, "\n";
+
+ c.Double(500);
+ c.AddFive(502);
+ c.StaticTriple(504);
+ TT.StaticTriple(504);
+ CC.StaticTriple(505);
+}
diff --git a/Test/dafny0/Trait/TraitCompile.dfy.expect b/Test/dafny0/Trait/TraitCompile.dfy.expect
new file mode 100644
index 00000000..f4f346de
--- /dev/null
+++ b/Test/dafny0/Trait/TraitCompile.dfy.expect
@@ -0,0 +1,18 @@
+
+Dafny program verifier finished with 23 verified, 0 errors
+Program compiled successfully
+Running...
+
+y=120
+x=12
+d=800
+a5=407
+t=1212
+z=30
+z'=30
+w=30
+d=1000
+a5=507
+t=1512
+t=1512
+t=1515