inheritance — examples
← all topics · 46 examples · page 1 of 1 · raw source ↓
Rejected at compile time: ES2128
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: CtorOverloadTests.cs::CtorBase_ArityMismatch_ES2128 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2128
namespace Test
open class Base {
var v: int
init(a: int) { v = a }
}
class Child : Base {
init() : base(1, 2) { }
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: CtorOverloadTests.cs::CtorDelegation_WithInheritance_BaseRunsOnce topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Base {
var stamps: int
init(seed: int) { stamps = stamps + seed }
}
class Derived : Base {
var extra: int
init(seed: int) : base(seed) { extra = 1 }
init() : this(50) { extra = extra + 2 }
}
func run() -> int {
let d = Derived()
return d.stamps + d.extra
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: CtorOverloadTests.cs::CtorVisibility_ProtectedInit_BaseChainRuns topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
var sides: int
protected init(sides: int) { self.sides = sides }
}
class Square : Shape {
init() : base(4) { }
}
func run() -> int {
let s = Square()
return s.sides
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ForwardReferenceTests.cs::RefData_Inherits_LaterOpenBase topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Dog : Animal {
extra: int
init(e: int) : base(4) { self.extra = e }
}
open class Animal {
legs: int
init(l: int) { self.legs = l }
}
func go() -> int {
let d = Dog(3)
return d.legs + d.extra
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: HierarchyExhaustivenessTests.cs::OpenBase_NoExhaustivenessCheck topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Base { init() {} }
class Leaf : Base { init() : base() {} }
func go() -> string {
let b: Base = Leaf()
return match b {
(l: Leaf) => "leaf"
default => "base"
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Data.cs::RefData_Inheritance_Override topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
init() { }
abstract func area() -> int
}
class Square : Shape {
side: int
init(s: int) : base() { self.side = s }
: func area() -> int { return self.side * self.side }
}
func go() -> int {
let sq = Square(5)
return sq.area()
}ILEmitterTests_Inheritance__Abstract_Func_On_Abstract_Class_Has_No_Body
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Abstract_Func_On_Abstract_Class_Has_No_Body topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
init() { }
abstract func area() -> int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Abstract_Modifier_Emits_Abstract_Class topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
init() { }
}ILEmitterTests_Inheritance__Added_Abstract_NotInstantiable_IsAbstractFlag
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Added_Abstract_NotInstantiable_IsAbstractFlag topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
init() { }
abstract func area() -> int
}Runs `go` → "dog"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Added_BaseCall_PassesArgs topic: inheritance status: verified
// verified behavior: Test.go(...) == "dog"
namespace Test
open class Animal {
species: string
init(s: string) { self.species = s }
}
class Dog : Animal {
name: string
init(n: string) : base("dog") { self.name = n }
}
func go() -> string {
let d = Dog("rex")
return d.species
}Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Added_InheritedFieldResolves topic: inheritance status: verified
// verified behavior: Test.go(...) == 42
namespace Test
open class Base {
n: int
init(n: int) { self.n = n }
}
class Derived : Base {
init() : base(42) { }
}
func go() -> int {
let d = Derived()
return d.n
}Runs `go` → 4
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Added_VirtualNotOverridden_UsesBase topic: inheritance status: verified
// verified behavior: Test.go(...) == 4
namespace Test
open class Animal {
init() { }
virtual func legs() -> int { return 4 }
}
class Snake : Animal {
init() : base() { }
}
func go() -> int {
// Snake doesn't override legs(): callvirt resolves to Animal's base body.
var a: Animal = Snake()
return a.legs()
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Added_VirtualOverride_DispatchesDerived topic: inheritance status: verified
// verified behavior: Test.go(...) == 2
namespace Test
open class Animal {
init() { }
virtual func sound() -> int { return 1 }
}
class Dog : Animal {
init() : base() { }
: func sound() -> int { return 2 }
}
func go() -> int {
// Base-typed local holding a derived instance — callvirt dispatches to Dog.
var a: Animal = Dog()
return a.sound()
}Runs `test` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Base_Class_Field_Read_Through_Subclass topic: inheritance status: verified
// verified behavior: Test.test(...) == 42
namespace Test
open class Base {
pub n: int
init(n: int) { self.n = n }
}
class Sub : Base {
init(n: int) : base(n) {}
}
func test() -> int {
let s = Sub(42)
return s.n
}Runs `go` → 16
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Func_Fulfills_Abstract_Parent topic: inheritance status: verified
// verified behavior: Test.go(...) == 16
namespace Test
abstract class Shape {
init() { }
abstract func area() -> int
}
class Square : Shape {
side: int
init(s: int) : base() { self.side = s }
: func area() -> int { return self.side * self.side }
}
func go() -> int {
let s = Square(4)
return s.area()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Func_Override_Uses_ReuseSlot_VTable topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Animal {
init() { }
virtual func speak() -> string = "..."
}
class Dog : Animal {
init() : base() { }
: func speak() -> string = "woof"
}Runs `go` → "woof"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Func_Overrides_Virtual_Parent topic: inheritance status: verified
// verified behavior: Test.go(...) == "woof"
namespace Test
open class Animal {
init() { }
virtual func speak() -> string = "..."
}
class Dog : Animal {
init() : base() { }
: func speak() -> string = "woof"
}
func go() -> string {
let d = Dog()
return d.speak()
}ILEmitterTests_Inheritance__Colon_Func_With_No_Matching_Parent_Is_ES2122
inheritance negative verifiedRejected at compile time: ES2122
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Func_With_No_Matching_Parent_Is_ES2122 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2122
namespace Test
open class Animal {
init() { }
}
class Dog : Animal {
init() : base() { }
: func bark() -> string = "woof"
}ILEmitterTests_Inheritance__Colon_Func_Without_Body_In_Concrete_Subclass_Is_ES2121
inheritance negative verifiedRejected at compile time: ES2121
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Func_Without_Body_In_Concrete_Subclass_Is_ES2121 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2121
namespace Test
abstract class Shape {
init() { }
abstract func area() -> int
}
class Square : Shape {
init() : base() { }
: func area() -> int
}Runs `go` → "dog"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Init_Calls_BaseCtor_With_Args topic: inheritance status: verified
// verified behavior: Test.go(...) == "dog"
namespace Test
open class Animal {
species: string
init(s: string) { self.species = s }
}
class Dog : Animal {
init() : base("dog") { }
}
func go() -> string {
let d = Dog()
return d.species
}Rejected at compile time: ES2128
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Init_Mismatched_BaseArgs_Is_ES2128 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2128
namespace Test
open class Animal {
name: string
init(n: string) { self.name = n }
}
class Dog : Animal {
init() : base() { }
}ILEmitterTests_Inheritance__Open_Class_Carries_Open_Flag_In_CLR_Metadata
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Open_Class_Carries_Open_Flag_In_CLR_Metadata topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Animal {
init() {}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Open_Modifier_Emits_NotSealed_NotAbstract topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Animal {
init() { }
}ILEmitterTests_Inheritance__Plain_Func_Shadowing_Virtual_Parent_Is_ES2120
inheritance negative verifiedRejected at compile time: ES2120
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Plain_Func_Shadowing_Virtual_Parent_Is_ES2120 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2120
namespace Test
open class Animal {
init() { }
virtual func speak() -> string = "..."
}
class Dog : Animal {
init() : base() { }
func speak() -> string = "woof"
}ILEmitterTests_Inheritance__Polymorphic_Dispatch_Through_Base_Class_Reference
inheritance runnable verifiedRuns `goDog` → "woof"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Polymorphic_Dispatch_Through_Base_Class_Reference topic: inheritance status: verified
// verified behavior: Test.goDog(...) == "woof"
namespace Test
open class Animal {
init() { }
virtual func speak() -> string = "..."
}
class Cat : Animal {
init() : base() { }
: func speak() -> string = "meow"
}
class Dog : Animal {
init() : base() { }
: func speak() -> string = "woof"
}
func goCat() -> string {
let c = Cat()
return c.speak()
}
func goDog() -> string {
let d = Dog()
return d.speak()
}ILEmitterTests_Inheritance__Sealed_Default_Carries_Sealed_Flag_In_CLR_Metadata
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Sealed_Default_Carries_Sealed_Flag_In_CLR_Metadata topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Locked {
init() {}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Sealed_Default_Emits_Sealed_Class topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Dog {
init() { }
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Sealed_Explicit_Emits_Sealed_Class topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Cat {
init() { }
}ILEmitterTests_Inheritance__Subclass_Of_Abstract_Class_Has_Base_Type_Set
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Subclass_Of_Abstract_Class_Has_Base_Type_Set topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
abstract class Shape {
init() { }
}
class Square : Shape {
init() : base() { }
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Subclass_Of_Open_Class_Has_Base_Type_Set topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Animal {
init() { }
}
class Dog : Animal {
init() : base() { }
}ILEmitterTests_Inheritance__Subclass_Of_Sealed_Implicitly_Fails_Cleanly
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Subclass_Of_Sealed_Implicitly_Fails_Cleanly topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
class Cat {
init() { }
}
class Bob : Cat {
init() { }
}ILEmitterTests_Inheritance__Subclass_With_Interface_AND_Base_Class_Reports_Both
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Subclass_With_Interface_AND_Base_Class_Reports_Both topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface INamed { func name() -> string }
open class Animal {
init() { }
}
class Dog : Animal, INamed {
init() : base() { }
func name() -> string = "dog"
}Runs `run` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Two_Level_PassThrough_To_Fulfill topic: inheritance status: verified
// verified behavior: Test.run(...) == 42
namespace Test
abstract class Top {
init() { }
abstract func go() -> int
}
abstract class Middle : Top {
init() : base() { }
}
class Leaf : Middle {
init() : base() { }
: func go() -> int = 42
}
func run() -> int { return Leaf().go() }ILEmitterTests_Inheritance__Virtual_Func_On_Open_Class_Emits_Virtual_NewSlot
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Virtual_Func_On_Open_Class_Emits_Virtual_NewSlot topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Animal {
init() { }
virtual func speak() -> string = "<silence>"
}ILEmitterTests_Inheritance__Virtual_Func_On_Sealed_Class_Reports_ES2126
inheritance negative verifiedRejected at compile time: ES2126
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Virtual_Func_On_Sealed_Class_Reports_ES2126 topic: inheritance status: verified
// verified behavior: reports diagnostic ES2126
namespace Test
class Cat {
init() { }
virtual func meow() -> string = "meow"
}ILEmitterTests_Inheritance__Virtual_Method_Calls_Another_Virtual_On_Same_Type
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Virtual_Method_Calls_Another_Virtual_On_Same_Type topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Computer {
init() {}
virtual func step() -> int = 1
virtual func run() -> int = self.step() + self.step()
}
class Faster : Computer {
init() : base() {}
: func step() -> int = 10
}
func test() -> int {
let f = Faster()
return f.run()
}Runs `test` → 25
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::Abstract_Method_Implemented_By_Subclass topic: inheritance status: verified
// verified behavior: Test.test(...) == 25
namespace Test
abstract class Shape {
init() {}
abstract func area() -> int
}
class Square : Shape {
pub side: int
init(s: int) : base() { self.side = s }
: func area() -> int = self.side * self.side
}
func test() -> int {
let sq = Square(5)
return sq.area()
}Runs `test` → "alice"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::Inheritance_Base_Constructor_With_Args topic: inheritance status: verified
// verified behavior: Test.test(...) == "alice"
namespace Test
open class Named {
pub name: string
init(name: string) { self.name = name }
}
class Greet : Named {
init(name: string) : base(name) {}
}
func test() -> string {
let g = Greet("alice")
return g.name
}Runs `test` → "dog"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::Inheritance_Three_Level_Chain_Pin topic: inheritance status: verified
// verified behavior: Test.test(...) == "dog"
namespace Test
open class Animal {
pub kind: string
init(k: string) { self.kind = k }
}
open class Mammal : Animal {
init(k: string) : base(k) {}
}
class Dog : Mammal {
init() : base("dog") {}
}
func test() -> string {
let d = Dog()
return d.kind
}ILEmitterTests3__RefData_Virtual_Method_Overridden_Multiple_Levels_Pin
inheritance runnable verifiedRuns `test` → "ABC"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::RefData_Virtual_Method_Overridden_Multiple_Levels_Pin topic: inheritance status: verified
// verified behavior: Test.test(...) == "ABC"
namespace Test
open class A {
init() {}
virtual func name() -> string = "A"
}
open class B : A {
init() : base() {}
: func name() -> string = "B"
}
class C : B {
init() : base() {}
: func name() -> string = "C"
}
func test() -> string {
let a = A()
let b = B()
let c = C()
return a.name() + b.name() + c.name()
}Runs `test` → "noise"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::Virtual_Method_Default_Used_When_Not_Overridden topic: inheritance status: verified
// verified behavior: Test.test(...) == "noise"
namespace Test
open class Animal {
init() {}
virtual func sound() -> string = "noise"
}
func test() -> string {
let a = Animal()
return a.sound()
}Runs `test` → "woof"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests3.cs::Virtual_Method_Override_Wins topic: inheritance status: verified
// verified behavior: Test.test(...) == "woof"
namespace Test
open class Animal {
init() {}
virtual func sound() -> string = "noise"
}
class Dog : Animal {
init() : base() {}
: func sound() -> string = "woof"
}
func test() -> string {
let d = Dog()
return d.sound()
}PrimaryCtorCaptureTests__Header_WithBaseClass_PrimaryCallsParameterlessBase
inheritance unknown verifiedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: PrimaryCtorCaptureTests.cs::Header_WithBaseClass_PrimaryCallsParameterlessBase topic: inheritance status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
open class Node {
var id: int = 41
}
class Leaf(label: string) : Node {
func tag() -> string { return label + self.id.ToString() }
}
func run() -> string {
let l = Leaf("n")
return l.tag()
}Showcase example
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: symbols.es topic: inheritance status: verified
// hand-authored, idiomatic E# — verified through the E# compiler
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: symbols.es topic: narrowing status: verified
// hand-authored, idiomatic E# — verified through the E# compiler
namespace Demo
// ═════════════════════════════════════════════════════════════════════════════
// Type narrowing & downcasting — the language form the in-house LSP needs to take an
// open symbol and discriminate it into its concrete kind. The shape is the LSP's own:
// a symbol table over a CLOSED `abstract class` hierarchy (a base you must subclass,
// sealed leaves you instantiate — E#'s base-or-sealed inheritance stance), dispatched
// with an exhaustive `match` type pattern and ZERO downcasts.
//
// `match s { (t: TypeSym) => … (m: MethodSym) => … }` is the whole point: each arm is an
// `isinst` test that binds the narrowed value, and because the hierarchy is closed the
// compiler checks every leaf is handled — add a leaf and every match that forgot it warns.
// A guard (`if m.isStatic`) refines an arm; the `=>` form is the value-producing body.
// ═════════════════════════════════════════════════════════════════════════════
// The closed hierarchy. `abstract class` is a base that must be subclassed; each leaf
// is a plain (sealed) `class`, constructed with its `init` and chaining `: base(...)`.
abstract class Sym {
name: string
init(n: string) { self.name = n }
}
class TypeSym : Sym {
arity: int
init(n: string, a: int) : base(n) { self.arity = a }
}
class MethodSym : Sym {
isStatic: bool
init(n: string, s: bool) : base(n) { self.isStatic = s }
}
class FieldSym : Sym {
fieldType: string
init(n: string, t: string) : base(n) { self.fieldType = t }
}
// One hover line per symbol kind — an exhaustive type-pattern match over the closed set.
// No `default`: the compiler knows Sym's leaves are TypeSym / MethodSym / FieldSym, so
// adding a fourth would light up this match. A guarded arm distinguishes static methods.
func (s: Sym) describe() -> string =
match s {
(t: TypeSym) => "type {t.name}/{t.arity}"
(m: MethodSym) if m.isStatic => "static {m.name}"
(m: MethodSym) => "func {m.name}"
(f: FieldSym) => "{f.name}: {f.fieldType}"
}
// The open-world fallback. When the value is genuinely an open `object` (the BCL boundary
// the LSP can't avoid), `is` / `as` / `as!` carry the narrowing: `is T` tests and
// smart-casts, `as T` yields `T?` and composes with `??`, `as!` asserts and throws.
func openKind(o: object) -> string {
if o is Sym {
// smart-cast: `o` is a `Sym` here, no rebind — dispatch through describe's match.
// `describe` is a value-receiver method (its first parameter is `Sym`), so it is
// called as a method on the narrowed value.
return o.describe()
}
let n = o as int // n : int? — the safe cast, composing with ??
return "raw {n ?? -1}"
}
// The entry point — a `class Program` whose `main` IS the program (the compiler
// constructs it and calls `.main()`). Builds a few symbols and renders them.
class Program {
func main() -> string {
let symbols = List<Sym>()
symbols.Add(TypeSym("Point", 0))
symbols.Add(MethodSym("origin", true))
symbols.Add(MethodSym("translate", false))
symbols.Add(FieldSym("x", "int"))
let sb = System.Text.StringBuilder()
var i = 0
while i < symbols.Count {
if i > 0 { sb.Append("; ") }
sb.Append(symbols[i].describe())
i += 1
}
// …and the open-world path over a boxed primitive.
sb.Append(" | ")
let boxed: object = 42
sb.Append(openKind(boxed))
return sb.ToString()
}
}
ILEmitterTests_Inheritance__Abstract_Func_Outside_Abstract_Class_Reports_ES2125
inheritance negativeRejected at compile time: ES2125
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Abstract_Func_Outside_Abstract_Class_Reports_ES2125 topic: inheritance status: unverified
// verified behavior: reports diagnostic ES2125
namespace Test
open class Animal {
init() { }
abstract func voice() -> string
}Rejected at compile time: ES2124
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Inheritance.cs::Colon_Marker_Without_Inheritance_Header_Is_ES2124 topic: inheritance status: unverified
// verified behavior: reports diagnostic ES2124
namespace Test
class Solo {
init() { }
: func go() -> int = 1
}