Inheritance

Overview

Single inheritance of classes, and without field expressions or superclass constructor expressions (just values)

Syntax

Extend the class of declarations by:
 
DecAtom ::= ...
| ClassKind class Id Params extends Id Vals { ClassBody } (DecAtom Class)
 

Dynamic semantics

Extend the grammar of resources:
 
Resource ::= ...
| ClassKind class Params extends Id Vals { ClassRes }{ ClassBody } (Resource Class)
 
The reduction relation is extended with (when CV1 contains all the fields and methods of CV3):
 
L[CK1 class I1 PS1 extends I2 VS2 { CV1 } D] | secret I1; L[D] | (Redn Class)
L<I2 = CK2 class PS2 extends I3 VS3 { CV2 CV3 }{ CB2 }> L<I1 = CK1 class PS1 extends I2 VS2 { CV2[VS2/PS2] CV1 }{ CV1 }>
L<I2 = CK2 class PS2 extends I3 VS3 { CV2 CV3 }{ CB2 }>
 

Static semantics

Extend the grammar of contexts with type rules for classes:
 
ConAtom ::= ...
| Id : ClassKind class Types extends ClassName { ClassType } (ConAtom Class)
 
Judgements Context  ClassName extends ClassName:
 

(Extends Defn)
C1 I : CK class TS extends CN { CT } C2 I extends CN
 
Extend the judgements Context  Context : context with:
 
C0 C1 CN : class { CT2 }
C0 C1 TS : types
C0 | C1 CT1 : class type
C0 C1 CT1 <: CT2

(Context Class) [C1 = (I1 : CK class TS extends CN { CT1 })]
C C1 : context
 
Extend the judgements for declarations Context  Dec : Context with:
 
C0 CN2 : [local] class
C0 CN2 : class { CT2 CT3 }
C0 CN2 (TL2) : constructor
C0 C1 ((PL1) : (TL1)) : C2
C0 C1 C2 ES2 : TS2
C0 | C1 | C2 | I1 CB1 : CT1
C0 C1 CT1 <: CT3
C0 C1 CT2 CT1 : class type

(Context Class) [C1 = (I1 : local class (TL1) extends CN2 { CT2 CT1 })]
C0 (local class I1 (PL1) extends CN2 (EL2) { CB1 }) : C1
 

Subtyping

Subsumption rules:
 
C C0 <: C1
C D : C0

(Dec Subsumption)
C D : C1
 
 
 
 
 
 
 
 
 
 
 
C A : T1
C T1 <: T2

(Assign Subsumption)
C A : T2
 
 
 
 
 
 
 
 
 
 
 
C V: T1
C T1 <: T2

(Val Subsumption)
C V : T2
 
Judgements for subtyping types Con  Type <: Type:
 
C CN1 extends CN2

(SubType Object)
C object CN1 <: object CN2
 
 
 
 
 
 
 
 
 
 
 
C CN1 extends CN2

(SubType Record)
C record CN1 <: record CN2
 
 
 
 
 
 
 
 
 
 
 

(SubType Refl)
C T <: T
 
 
 
 
 
 
 
 
 
 
 
C T1 <: T2
C T2 <: T3

(SubType Trans)
C T1 <: T3
 
Judgements for subtyping types Con  Types <: Types:
 
C T11 <: T12
...
C Tn1 <: Tn2

(SubTypes)
C (T11, ... , Tn1) <: (T12, ... , Tn2)
 
Judgements for subtyping contexts Con  Con <: Con:
 
C T1 <: T2

(SubContext Id)
C (I : T1;) <: (I : T2;)
 
 
 
 
 
 
 
 
 
 
 

(SubContext Refl)
C C1 <: C1
 
 
 
 
 
 
 
 
 
 
 
C C1 <: C2
C C2 C3 <: C4

(SubContext Comp)
C C1 C3 <: C2 C4
 
 
 
 
 
 
 
 
 
 
 

(SubContext Top)
C C1 <: ()
 
Judgements for subtyping class types Con  ClassType <: ClassType:
 
C (FT1 FT5) <: (FT2 FT6
C FT3 <: FT4
C (MT1 MT3) <: (MT2 MT4)

(SubClassType)
C abstract { FT1 MT1 } static { FT3 } FT5 MT3 <:
abstract { FT2 MT2 } static { FT4 } FT6 MT4
 
Judgements for subtyping field types Con  FieldType <: FieldType:
 
C T1 <: T2

(SubFieldType Id)
C field I : T1; <: field I : T2;
 
 
 
 
 
 
 
 
 
 
 
C FT1 <: FT2
C FT3 <: FT4

(SubFieldTypeComp)
C FT1 FT3 <: FT2 FT4
 
 
 
 
 
 
 
 
 
 
 

(SubFieldType Top)
C FT1 <: ()
 
Judgements for subtyping method types Con  MethodType <: MethodType:
 
C T1 <: T2
C TS2 <: TS1

(SubMethodType Id)
C MK method I TS1 : T1; <: MK method I TS2 : T2;
 
 
 
 
 
 
 
 
 
 
 
C MT1 <: MT2
C MT3 <: MT4

(SubMethodType Comp)
C MT1 MT3 <: MT2 MT4
 
 
 
 
 
 
 
 
 
 
 

(SubMethodType Top)
C MT1 <: ()