diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/object/good/override.tig | |
Diffstat (limited to 'tiger-compiler/tests/object/good/override.tig')
| -rwxr-xr-x | tiger-compiler/tests/object/good/override.tig | 28 |
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 |
