From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/tests/object/good/override.tig | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tiger-compiler/tests/object/good/override.tig (limited to 'tiger-compiler/tests/object/good/override.tig') diff --git a/tiger-compiler/tests/object/good/override.tig b/tiger-compiler/tests/object/good/override.tig new file mode 100755 index 0000000..550d3cd --- /dev/null +++ b/tiger-compiler/tests/object/good/override.tig @@ -0,0 +1,28 @@ +let + class C + { + var a := 0 + method m() : int = self.a + } + class D extends C + { + var b := 9 + /* Override C.m(). */ + method m() : int = self.a + self.b + } + var d : D := new D + /* Valid upcast due to inclusion polymorphism. */ + var c : C := d + in + c.a := 42; + /* Note that accessing `c.b' is not allowed, since `c' is + statically known as a `C', even though it is actually a `D' + at run time. */ + let + /* Polymorphic call. */ + var res := c.m() + in + print_int(res); + print("\n") + end +end \ No newline at end of file -- cgit v1.2.3