pointers — examples
← all topics · 135 examples · page 2 of 3 · raw source ↓
Runs `checkAfterSet` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_NilCheck topic: pointers status: verified
// verified behavior: Test.checkAfterSet(...) == 2
namespace Test
data Inner { var x: int }
ref data Box {
inner: *Inner
}
func checkBoth() -> int {
var b = Box()
if b.inner == nil { return 1 }
return 0
}
func checkAfterSet() -> int {
var b = Box()
b.inner = new Inner { x: 5 }
if b.inner != nil { return 2 }
return 0
}ILEmitterTests_HeapPointer__HeapPointer_NonNil_Compare_Returns_False_To_Nil
pointers runnable verifiedRuns `test` → false
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_NonNil_Compare_Returns_False_To_Nil topic: pointers status: verified
// verified behavior: Test.test(...) == false
namespace Test
data Node { value: int }
func test() -> bool {
let n: *Node = new Node { value: 7 }
return n == nil
}Runs `test` → 0
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_ReceiverMutatesThroughPointer topic: pointers status: verified
// verified behavior: Test.test(...) == 0
namespace Test
data Health {
var current: int
var max: int
}
ref data Entity {
hp: *Health
}
func takeDamage(e: Entity, amount: int) {
if e.hp == nil { return }
e.hp.current -= amount
if e.hp.current < 0 {
e.hp.current = 0
}
}
func test() -> int {
var e = Entity()
e.hp = new Health { current: 100, max: 100 }
e.takeDamage(30)
e.takeDamage(80)
return e.hp.current
}Runs `sum` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_ReturnType topic: pointers status: verified
// verified behavior: Test.sum(...) == 60
namespace Test
data Node {
value: int
next: *Node
}
func prepend(head: *Node, value: int) -> *Node {
return new Node { value: value, next: head }
}
func sum() -> int {
var list: *Node = nil
list = prepend(list, 10)
list = prepend(list, 20)
list = prepend(list, 30)
var total = 0
var cur = list
while cur != nil {
total += cur.value
cur = cur.next
}
return total
}Runs `sum` → 6
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_SelfReferential_StaysStruct topic: pointers status: verified
// verified behavior: Test.sum(...) == 6
namespace Test
data Node {
value: int
next: *Node
}
func sum() -> int {
var n3: *Node = new Node { value: 3, next: nil }
var n2: *Node = new Node { value: 2, next: n3 }
var n1: *Node = new Node { value: 1, next: n2 }
var total = 0
var cur = n1
while cur != nil {
total += cur.value
cur = cur.next
}
return total
}Rejected at compile time: ES2003
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_StarRefData_Error topic: pointers status: verified
// verified behavior: reports diagnostic ES2003
namespace Test
ref data Connection {
id: int
}
ref data Manager {
conn: *Connection
}ILEmitterTests_HeapPointer__HeapPointer_StructProtocol_ImplicitSatisfaction
pointers runnable verifiedRuns `test` → "Alice"
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::HeapPointer_StructProtocol_ImplicitSatisfaction topic: pointers status: verified
// verified behavior: Test.test(...) == "Alice"
namespace Test
interface IDescribable {
func describe() -> string
}
data Client : IDescribable {
name: string
}
func describe(c: Client) -> string {
return c.name
}
func printInfo(d: IDescribable) -> string {
return d.describe()
}
func test() -> string {
let c = Client { name: "Alice" }
return printInfo(c)
}Runs `check` → true
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_AllMethodsRequired topic: pointers status: verified
// verified behavior: Test.check(...) == true
namespace Test
data Pair {
var a: int
var b: int
}
func getA(p: *Pair) -> int {
return p.a
}
interface INeedsTwo {
func getA() -> int
func getB() -> int
}
func check() -> bool {
return true
}Runs `test` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_Compiles topic: pointers status: verified
// verified behavior: Test.test(...) == 60
namespace Test
data Node : ISummable {
value: int
next: *Node
}
func sum(head: *Node) -> int {
var total = 0
var current = head
while current != nil {
total += current.value
current = current.next
}
return total
}
interface ISummable {
func sum() -> int
}
func report(s: ISummable) -> int {
return s.sum()
}
func test() -> int {
var list: *Node = nil
list = new Node { value: 10, next: nil }
list = new Node { value: 20, next: list }
list = new Node { value: 30, next: list }
return report(list)
}Runs `test` → 30
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_MixedMethodSet topic: pointers status: verified
// verified behavior: Test.test(...) == 30
namespace Test
data Acc : IAccumulator {
var total: int
}
func get(a: Acc) -> int {
return a.total
}
func add(a: *Acc, n: int) {
a.total += n
}
interface IAccumulator {
func get() -> int
func add(n: int)
}
func useAcc(a: IAccumulator) -> int {
a.add(10)
a.add(20)
return a.get()
}
func test() -> int {
var a: *Acc = new Acc { total: 0 }
return useAcc(a)
}Runs `testValue` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_ValueReceiverInBothSets topic: pointers status: verified
// verified behavior: Test.testValue(...) == 42
namespace Test
data Counter : IReadable {
var value: int
}
func current(c: Counter) -> int {
return c.value
}
interface IReadable {
func current() -> int
}
func fetch(r: IReadable) -> int {
return r.current()
}
func testValue() -> int {
let c = Counter { value: 42 }
return fetch(c)
}Runs `check` → true
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_ValueTypeDoesNotSatisfy topic: pointers status: verified
// verified behavior: Test.check(...) == true
namespace Test
data Widget : IDescribable {
var x: int
}
func describe(w: *Widget) -> string {
return "widget"
}
interface IDescribable {
func describe() -> string
}
func check() -> bool {
return true
}Runs `test` → 99
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_HeapPointer.cs::PointerProtocol_WrapperHasDelegateMethods topic: pointers status: verified
// verified behavior: Test.test(...) == 99
namespace Test
data Item : IValued {
var x: int
}
func value(i: *Item) -> int {
return i.x
}
interface IValued {
func value() -> int
}
func getValue(v: IValued) -> int {
return v.value()
}
func test() -> int {
var item: *Item = new Item { x: 99 }
return getValue(item)
}Runs `go` → 43
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_PointerOnlyConformance_Wrapper topic: pointers status: verified
// verified behavior: Test.go(...) == 43
namespace Test
data Inner { var n: int }
func bump(i: *Inner) { i.n += 1 }
func value(i: Inner) -> int = i.n
data Counter : ICounter { *Inner }
interface ICounter { func bump(), func value() -> int }
func tick(c: ICounter) -> int { c.bump() return c.value() }
func go() -> int {
var c: *Counter = new Counter { Inner: new Inner { n: 42 } }
return tick(c)
}Runs `go` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::PointerOnlyReceiver_Declared_SatisfiedViaWrapper topic: pointers status: verified
// verified behavior: Test.go(...) == 60
namespace Test
data Node : ISummable { value: int, next: *Node }
func sum(head: *Node) -> int {
var total = 0
var current = head
while current != nil {
total += current.value
current = current.next
}
return total
}
interface ISummable { func sum() -> int }
func report(s: ISummable) -> int { return s.sum() }
func go() -> int {
var list: *Node = nil
list = new Node { value: 10, next: nil }
list = new Node { value: 20, next: list }
list = new Node { value: 30, next: list }
return report(list)
}Runs `go` → 30
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::Dictionary_PointerValue_Iterate topic: pointers status: verified
// verified behavior: Test.go(...) == 30
namespace Test
data Box { n: int }
func go() -> int {
var m = Dictionary<string, *Box>()
m["a"] = new Box { n: 10 }
m["b"] = new Box { n: 20 }
return m["a"].n + m["b"].n
}Runs `go` → 99
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::DictionaryStringToPointer topic: pointers status: verified
// verified behavior: Test.go(...) == 99
namespace Test
data Box { n: int }
func go() -> int {
var m = Dictionary<string, *Box>()
m["a"] = new Box { n: 99 }
return m["a"].n
}ILEmitterTests_PointerCollections__ExplicitListOfPointers_AddThenIndex
pointers runnable verified ×2Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::ExplicitListOfPointers_AddThenIndex topic: pointers status: verified
// verified behavior: Test.go(...) == 7
namespace Test
data Box { n: int }
func go() -> int {
var xs = List<*Box>()
xs.Add(new Box { n: 7 })
return xs[0].n
}Runs `go` → 12
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::ExplicitListOfPointers_ForIn topic: pointers status: verified
// verified behavior: Test.go(...) == 12
namespace Test
data Box { n: int }
func go() -> int {
var xs = List<*Box>()
xs.Add(new Box { n: 5 })
xs.Add(new Box { n: 7 })
var t = 0
for b in xs { t += b.n }
return t
}Runs `go` → 6
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::GenericData_HoldingPointer topic: pointers status: verified
// verified behavior: Test.go(...) == 6
namespace Test
data Box { n: int }
data Cell<T> { value: T }
func go() -> int {
let c = Cell<*Box> { value: new Box { n: 6 } }
return c.value.n
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::GenericData_Nested_PointerInner topic: pointers status: verified
// verified behavior: Test.go(...) == 3
namespace Test
data Box { n: int }
data Cell<T> { value: T }
func go() -> int {
let c = Cell<Cell<*Box>> { value: Cell<*Box> { value: new Box { n: 3 } } }
return c.value.value.n
}Runs `go` → 8
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::GenericData_PointerField_Mutate topic: pointers status: verified
// verified behavior: Test.go(...) == 8
namespace Test
data Box { var n: int }
data Cell<T> { value: T }
func go() -> int {
let c = Cell<*Box> { value: new Box { n: 7 } }
c.value.n += 1
return c.value.n
}Runs `go` → 20
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfInts_Index topic: pointers status: verified
// verified behavior: Test.go(...) == 20
namespace Test
func go() -> int {
let xs = [10, 20, 30]
return xs[1]
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfPointers_Count topic: pointers status: verified
// verified behavior: Test.go(...) == 3
namespace Test
data Box { n: int }
func go() -> int {
let xs = [new Box { n: 1 }, new Box { n: 2 }, new Box { n: 3 }]
return xs.Count
}Runs `go` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfPointers_ForIn_Sum topic: pointers status: verified
// verified behavior: Test.go(...) == 60
namespace Test
data Box { n: int }
func go() -> int {
let xs = [new Box { n: 10 }, new Box { n: 20 }, new Box { n: 30 }]
var total = 0
for b in xs {
total += b.n
}
return total
}Runs `go` → 10
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfPointers_IndexZero topic: pointers status: verified
// verified behavior: Test.go(...) == 10
namespace Test
data Box { n: int }
func go() -> int {
let xs = [new Box { n: 10 }, new Box { n: 20 }]
return xs[0].n
}Runs `go` → 60
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfValueData_ForIn_Sum topic: pointers status: verified
// verified behavior: Test.go(...) == 60
namespace Test
data Box { n: int }
func go() -> int {
let xs = [Box { n: 10 }, Box { n: 20 }, Box { n: 30 }]
var total = 0
for b in xs {
total += b.n
}
return total
}Runs `go` → 20
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::List_OfValueData_Index topic: pointers status: verified
// verified behavior: Test.go(...) == 20
namespace Test
data Box { n: int }
func go() -> int {
let xs = [Box { n: 10 }, Box { n: 20 }]
return xs[1].n
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::NestedListOfPointerLists topic: pointers status: verified
// verified behavior: Test.go(...) == 2
namespace Test
data Box { n: int }
func go() -> int {
var outer = List<List<*Box>>()
var inner = List<*Box>()
inner.Add(new Box { n: 1 })
inner.Add(new Box { n: 2 })
outer.Add(inner)
return outer[0].Count
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::NestedListOfPointers_IndexDeref topic: pointers status: verified
// verified behavior: Test.go(...) == 2
namespace Test
data Box { n: int }
func go() -> int {
var outer = List<List<*Box>>()
var inner = List<*Box>()
inner.Add(new Box { n: 1 })
inner.Add(new Box { n: 2 })
outer.Add(inner)
return outer[0][1].n
}Runs `go` → 3
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerList_CountAfterAdds topic: pointers status: verified
// verified behavior: Test.go(...) == 3
namespace Test
data Box { n: int }
func go() -> int {
var xs = List<*Box>()
xs.Add(new Box { n: 1 })
xs.Add(new Box { n: 2 })
xs.Add(new Box { n: 3 })
return xs.Count
}Runs `go` → 6
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerList_IterateAndMutate topic: pointers status: verified
// verified behavior: Test.go(...) == 6
namespace Test
data Box { var n: int }
func go() -> int {
let xs = [new Box { n: 1 }, new Box { n: 2 }, new Box { n: 3 }]
for b in xs { b.n += 0 }
var t = 0
for b in xs { t += b.n }
return t
}Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerList_NestedFieldAccess topic: pointers status: verified
// verified behavior: Test.go(...) == 7
namespace Test
data Inner { v: int }
data Outer { inner: *Inner }
func go() -> int {
let xs = [new Outer { inner: new Inner { v: 7 } }]
return xs[0].inner.v
}Runs `go` → 9
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerList_PassToValueDataMethod topic: pointers status: verified
// verified behavior: Test.go(...) == 9
namespace Test
data Box { n: int }
func sumList(xs: List<*Box>) -> int {
var t = 0
for b in xs { t += b.n }
return t
}
func go() -> int {
let xs = [new Box { n: 4 }, new Box { n: 5 }]
return sumList(xs)
}Runs `go` → 9
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerListField_RoundTrip topic: pointers status: verified
// verified behavior: Test.go(...) == 9
namespace Test
data Box { n: int }
data Bag { items: List<*Box> }
func go() -> int {
var bag = Bag { items: List<*Box>() }
bag.items.Add(new Box { n: 9 })
return bag.items[0].n
}Runs `go` → 8
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerListParam_Sum topic: pointers status: verified
// verified behavior: Test.go(...) == 8
namespace Test
data Box { n: int }
func total(xs: List<*Box>) -> int {
var t = 0
for b in xs { t += b.n }
return t
}
func go() -> int {
var xs = List<*Box>()
xs.Add(new Box { n: 3 })
xs.Add(new Box { n: 5 })
return total(xs)
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerListReturn topic: pointers status: verified
// verified behavior: Test.go(...) == 2
namespace Test
data Box { n: int }
func build() -> List<*Box> {
var xs = List<*Box>()
xs.Add(new Box { n: 1 })
xs.Add(new Box { n: 2 })
return xs
}
func go() -> int {
let xs = build()
return xs.Count
}Runs `go` → 2
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::PointerReturnedFromListBoundMethod topic: pointers status: verified
// verified behavior: Test.go(...) == 2
namespace Test
data Box { n: int }
func go() -> int {
var xs = List<*Box>()
xs.Add(new Box { n: 1 })
xs.Add(new Box { n: 2 })
let last = xs[xs.Count - 1]
return last.n
}Runs `go` → 5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::TupleOfInts_Item topic: pointers status: verified
// verified behavior: Test.go(...) == 5
namespace Test
func go() -> int {
let t = (2, 5)
return t.Item2
}Runs `go` → 15
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::TupleOfMixed_PointerAndInt topic: pointers status: verified
// verified behavior: Test.go(...) == 15
namespace Test
data Box { n: int }
func go() -> int {
let t = (new Box { n: 5 }, 10)
return t.Item1.n + t.Item2
}Runs `go` → 7
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::TupleOfPointers_Destructure topic: pointers status: verified
// verified behavior: Test.go(...) == 7
namespace Test
data Box { n: int }
func go() -> int {
let (a, b) = (new Box { n: 2 }, new Box { n: 5 })
return a.n + b.n
}Runs `go` → 5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::TupleOfPointers_ItemDeref topic: pointers status: verified
// verified behavior: Test.go(...) == 5
namespace Test
data Box { n: int }
func go() -> int {
let t = (new Box { n: 2 }, new Box { n: 5 })
return t.Item2.n
}Runs `go` → 6
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerCollections.cs::TupleOfThreePointers_Destructure topic: pointers status: verified
// verified behavior: Test.go(...) == 6
namespace Test
data Box { n: int }
func go() -> int {
let (a, b, c) = (new Box { n: 1 }, new Box { n: 2 }, new Box { n: 3 })
return a.n + b.n + c.n
}Runs `go` → 33
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::Coercion_WrapperArg_ToByRefParam_Mutates topic: pointers status: verified
// verified behavior: Test.go(...) == 33
namespace Test
data Vec {
var x: int
var y: int
}
func shift(v: *Vec, dx: int, dy: int) {
v.x += dx
v.y += dy
}
func go() -> int {
var v: *Vec = new Vec { x: 1, y: 2 }
shift(v, 10, 20)
return v.x + v.y
}Runs `go` → 12
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::Coercion_WrapperPassedWithStarSyntax topic: pointers status: verified
// verified behavior: Test.go(...) == 12
namespace Test
data Cell {
var n: int
}
func inc(c: *Cell) {
c.n += 1
}
func go() -> int {
var p: *Cell = new Cell { n: 10 }
inc(*p)
inc(p)
return p.n
}Runs `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::Downgrade_ByRefParam_AliasesCallerLocal topic: pointers status: verified
// verified behavior: Test.go(...) == 42
namespace Test
data Counter {
var value: int
}
func bump(p: *Counter) {
p.value += 1
}
func go() -> int {
var c = Counter { value: 41 }
bump(&c)
return c.value
}ILEmitterTests_PointerModel__Downgrade_ByRefParam_RepeatedMutationAccumulates
pointers runnable verifiedRuns `go` → 42
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::Downgrade_ByRefParam_RepeatedMutationAccumulates topic: pointers status: verified
// verified behavior: Test.go(...) == 42
namespace Test
data Acc {
var n: int
}
func add(a: *Acc, amount: int) {
a.n += amount
}
func go() -> int {
var acc = Acc { n: 0 }
add(&acc, 10)
add(&acc, 20)
add(&acc, 12)
return acc.n
}Runs `go` → 6
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::Escaping_Param_StaysWrapper_RecursiveBuild topic: pointers status: verified
// verified behavior: Test.go(...) == 6
namespace Test
data Node {
value: int
next: *Node
}
func prepend(head: *Node, v: int) -> *Node {
return new Node { value: v, next: head }
}
func go() -> int {
var list: *Node = nil
list = prepend(list, 1)
list = prepend(list, 2)
list = prepend(list, 3)
var total = 0
var cur = list
while cur != nil {
total += cur.value
cur = cur.next
}
return total
}Runs `go` → 99
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::EscapingAddressOfLocal_AliasesLocal topic: pointers status: verified
// verified behavior: Test.go(...) == 99
namespace Test
data P {
var x: int
}
ref data H {
slot: *P
}
func go() -> int {
var local = P { x: 5 }
var h = H()
h.slot = &local
local.x = 99
return h.slot.x
}Runs `go` → 5
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_PointerModel.cs::EscapingAddressOfLocal_ForwardValue topic: pointers status: verified
// verified behavior: Test.go(...) == 5
namespace Test
data P {
var x: int
}
ref data H {
slot: *P
}
func go() -> int {
var local = P { x: 5 }
var h = H()
h.slot = &local
return h.slot.x
}