-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
OopsOverflow
committed
Jan 10, 2022
1 parent
7f92dd1
commit d768051
Showing
13 changed files
with
788 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Point(xc: Integer, yc: Integer) is { | ||
var x: Integer | ||
var y: Integer | ||
var name: String | ||
var super : Integer /* interdit */ | ||
|
||
def Point(xc: Integer, yc: Integer) is { | ||
this.x := xc; this.y := yc; name = "?"; | ||
} | ||
|
||
|
||
def setName(s: String) : Point is { | ||
this.name := s; | ||
result := this; | ||
return; | ||
this.super := s; /* interdit */ | ||
} | ||
|
||
def print() is { | ||
this.name.println(); | ||
this := new Point(0, 0); /* interdit */ | ||
this.x := this.super.x; /* incorrect */ | ||
result := this; /* interdit car pas de type de retour. */ | ||
} | ||
|
||
} | ||
{ | ||
p, p2: Point | ||
x: Integer | ||
is | ||
p1 := new Point(1, 5); | ||
p2 := new Point(2, 3); | ||
x := new Integer(1); /* interdit */ | ||
this := x; /* interdit */ | ||
result := x; /* interdit */ | ||
p2.setName("glop"); | ||
p1.print(); | ||
p2.print(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class A() is { | ||
var va: Integer | ||
def A() is { va := 1; } | ||
} | ||
class B() extends Integer /* Incorrect */ is { | ||
var vb: Integer | ||
def B() : Integer(12) is { vb := 2; } | ||
} | ||
class A2() extends B is { | ||
var w: Integer | ||
def A2() : B() is { w := 3; } | ||
} | ||
{ /* empty */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class A() is { | ||
var va: Integer | ||
def A() is {} | ||
} | ||
class B() extends Int is { /* incorrect: Int inconnue */ | ||
var vb: Integer | ||
def B() : Int(12) is { } | ||
} | ||
class A() extends B is { /* incorrect: double declaration de A */ | ||
var w: Integer | ||
def A() : B() is { } | ||
} | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class A() is { | ||
var va: Integer | ||
def A() is {} | ||
} | ||
class B() extends Int is { /* incorrect: Int inconnue */ | ||
var vb: Integer | ||
def B() : Int(12) is { } | ||
} | ||
class C() extends B is { /* incorrect: double declaration de A */ | ||
var w: Integer | ||
def C() : B() is { } | ||
} | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class A() is { | ||
var v: Integer | ||
def f() : Integer := this.v | ||
def A() is { v := 1; } | ||
} | ||
class A2() extends A is { | ||
var v: String | ||
var w: Integer | ||
def g() : String := this.v | ||
def A2() : A() is { v := "coucou"; w := 5; } | ||
} | ||
class A3() extends A2 is { | ||
var v: Integer | ||
def override f() : Integer := this.v | ||
def h() : Integer := (A this).v /* OK */ | ||
def h2(): String := (A2 this).v /* OK */ | ||
/* def k() : Integer := (A this).w /* Incorrect */ | ||
def A3() : A2() is { v := 5; } | ||
} | ||
class A4() extends A3 is { | ||
def A4() : A3() is {} | ||
} | ||
class B() extends A /* une soeur de A2 ! */ | ||
is { | ||
def B() : A() is { } | ||
} | ||
{ | ||
monA : A | ||
monA2 : A2 | ||
monA3 : A3 | ||
monA4 : A4 | ||
monB : B | ||
is | ||
monA := new A(); | ||
monA2 := new A2(); | ||
monA3 := new A3(); | ||
monA4 := new A4(); | ||
monB := new B(); | ||
|
||
/* (A monA3).h().toString.println(); /* KO: h indefinie dans A */ | ||
/* (A4 monA3); /* KO: pas de cast descendant */ | ||
(A3 monA4); /* OK */ | ||
/* (A3 monA); /* KO: pas de cast descendant */ | ||
/* (A2 monA4).k(); /* KO: pas de k() dans A2 */ | ||
/* (Unknown monA4); */ | ||
/* (B monA2); /* KO: A2 et B sons sans relation d'héritage */ | ||
/* (A2 monB); /* idem */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class A0() is { var va: Integer def A0() is { va := 1; } } | ||
class B() extends A is { var vb: Integer def B(): A() is { vb := 2; } } | ||
/* erreur A et B forment un circuit dans le graphe d'héritage */ | ||
class A() extends B is { var w: Integer def A(): B() is { w := 3; } } | ||
{ | ||
/* bloc vide: autorisé ! */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class A() is { | ||
var unA : A | ||
var result : Integer /* incorrect: identificateur reserve ! */ | ||
def f(result: Integer) is { } /* incorrect: identificateur reserve ! */ | ||
def g() is { | ||
result : Integer /* incorrect: identificateur reserve ! */ | ||
is | ||
result := 1; | ||
} | ||
def h() is { | ||
result := 1; /* incorrect: h() ne renvoie rien */ | ||
} | ||
def k() : Integer is { | ||
result := 1; /* correct */ | ||
} | ||
def k2() : Integer is { | ||
result := "coucou"; /* incorrect: pas du bon type */ | ||
} | ||
|
||
def A() is { result := unA; } /* result incorrect dans un constructeur */ | ||
} | ||
{ | ||
result : Integer /* incorrect: identificateur reserve ! */ | ||
is | ||
1; | ||
result.toString().println(); | ||
} |
Oops, something went wrong.