summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/object/good/override.tig
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/object/good/override.tig
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/tests/object/good/override.tig')
-rwxr-xr-xtiger-compiler/tests/object/good/override.tig28
1 files changed, 28 insertions, 0 deletions
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