summaryrefslogtreecommitdiff
path: root/Test/dafny0/ResolutionErrors.dfy
diff options
context:
space:
mode:
authorGravatar Rustan Leino <leino@microsoft.com>2011-05-28 18:08:55 -0700
committerGravatar Rustan Leino <leino@microsoft.com>2011-05-28 18:08:55 -0700
commitc86a3199caf050ef4af4ce5873ee7d6a27b501ab (patch)
tree47c42020587bffe014d52542bf8434b4a3a26683 /Test/dafny0/ResolutionErrors.dfy
parentc7c9cd675bf6024a8f725c84fe22e17d3deb7a98 (diff)
Dafny: added constructors
Diffstat (limited to 'Test/dafny0/ResolutionErrors.dfy')
-rw-r--r--Test/dafny0/ResolutionErrors.dfy27
1 files changed, 27 insertions, 0 deletions
diff --git a/Test/dafny0/ResolutionErrors.dfy b/Test/dafny0/ResolutionErrors.dfy
index cacc34be..9e7ad3b2 100644
--- a/Test/dafny0/ResolutionErrors.dfy
+++ b/Test/dafny0/ResolutionErrors.dfy
@@ -253,3 +253,30 @@ method DuplicateLabels(n: int) {
x := x + 1;
label DuplicateLabel: x := x + 1;
}
+
+// --------------- constructors -------------------------------------
+
+class ClassWithConstructor {
+ var y: int;
+ method NotTheOne() { }
+ constructor InitA() { }
+ constructor InitB() modifies this; { y := 20; }
+}
+
+class ClassWithoutConstructor {
+ method Init() modifies this; { }
+}
+
+method ConstructorTests()
+{
+ var o := new object; // fine: does not have any constructors
+
+ o := new ClassWithoutConstructor; // fine: don't need to call anything particular method
+ o := new ClassWithoutConstructor.Init(); // this is also fine
+
+ var c := new ClassWithConstructor.InitA();
+ c := new ClassWithConstructor; // error: must call a constructor
+ c := new ClassWithConstructor.NotTheOne(); // error: must call a constructor, not an arbitrary method
+ c := new ClassWithConstructor.InitB();
+ c.InitB(); // error: not allowed to call constructors except during allocation
+}