Skip to content

allocation — examples

← all topics · 72 examples · page 1 of 2 · raw source ↓

ILEmitterTests_New__Deprecated_Amp_IsNotAnError

allocation unknown verified ×3

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Deprecated_Amp_IsNotAnError   topic: allocation   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
data Box { n: int }
func go() -> int {
    let b = &Box { n: 7 }
    return b.n
}

ILEmitterTests_New__Ident_New_AsFieldName

allocation runnable verified

Runs `go` → 11

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsFieldName   topic: allocation   status: verified
// verified behavior: Test.go(...) == 11

namespace Test
data Holder { new: int }
func go() -> int {
    let h = Holder { new: 11 }
    return h.new
}

ILEmitterTests_New__Ident_New_AsFunctionName

allocation runnable verified

Runs `go` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsFunctionName   topic: allocation   status: verified
// verified behavior: Test.go(...) == 7

namespace Test
func new() -> int = 7
func go() -> int {
    return new()
}

Runs `go` → 8

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsFunctionParameter   topic: allocation   status: verified
// verified behavior: Test.go(...) == 8

namespace Test
func inc(new: int) -> int = new + 1
func go() -> int {
    return inc(7)
}

Runs `go` → 25

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsLetThenArithmetic   topic: allocation   status: verified
// verified behavior: Test.go(...) == 25

namespace Test
func go() -> int {
    let new = 5
    return new * new
}

ILEmitterTests_New__Ident_New_AsLocalVariable

allocation runnable verified

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsLocalVariable   topic: allocation   status: verified
// verified behavior: Test.go(...) == 5

namespace Test
func go() -> int {
    let new = 5
    return new
}

Runs `go` → 10

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsLoopVariableName   topic: allocation   status: verified
// verified behavior: Test.go(...) == 10

namespace Test
func go() -> int {
    var new = 0
    for i in 0..5 { new += i }
    return new
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_AsMutableVariable   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
func go() -> int {
    var new = 1
    new += 2
    return new
}

Runs `go` → 1

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_FollowedByComparison_NotTriggered   topic: allocation   status: verified
// verified behavior: Test.go(...) == 1

namespace Test
func go() -> int {
    let new = 5
    return new < 10 ? 1 : 0
}

Runs `go` → 4

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Ident_New_LowercaseTypeNotTriggered   topic: allocation   status: verified
// verified behavior: Test.go(...) == 4

namespace Test
func go() -> int {
    var new = 1
    let other = 3
    return new + other
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::IL_New_EmitsHeapAllocation   topic: allocation   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    let n = new Node { value: 7, next: nil }
    return n.value
}

Compiles

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::IL_New_LocalIsHeapPointerWrapper   topic: allocation   status: verified
// compiles cleanly (no auto-run claim was extracted)

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    var n: *Node = new Node { value: 7, next: nil }
    return n.value
}

Rejected at compile time: ES2144

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Neg_NewExternalGeneric_IsES2144   topic: allocation   status: verified
// verified behavior: reports diagnostic ES2144

namespace Test
func go() -> int {
    let xs = new List<int>()
    return 0
}

Rejected at compile time: ES2144

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Neg_NewExternalType_IsES2144   topic: allocation   status: verified
// verified behavior: reports diagnostic ES2144

namespace Test
func go() -> int {
    let s = new StringBuilder { }
    return 0
}

ILEmitterTests_New__Neg_NewRefData_IsES2003

allocation negative verified ×2

Rejected at compile time: ES2003

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::Neg_NewRefData_IsES2003   topic: allocation   status: verified
// verified behavior: reports diagnostic ES2003

namespace Test
ref data R {
    x: int
    init(x: int) { self.x = x }
}
func go() -> int {
    let r = new R { x: 1 }
    return r.x
}

ILEmitterTests_New__New_AsConditionArgument

allocation runnable verified

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_AsConditionArgument   topic: allocation   status: verified
// verified behavior: Test.go(...) == true

namespace Test
data Box { n: int }
func positive(b: *Box) -> bool = b.n > 0
func go() -> bool {
    if positive(new Box { n: 3 }) {
        return true
    }
    return false
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_AsExpressionBodiedReturn   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Point { x: int, y: int }
func make() -> *Point = new Point { x: 1, y: 2 }
func go() -> int {
    let p = make()
    return p.x + p.y
}

ILEmitterTests_New__New_AsFunctionArgument

allocation runnable verified

Runs `go` → 8

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_AsFunctionArgument   topic: allocation   status: verified
// verified behavior: Test.go(...) == 8

namespace Test
data Box { n: int }
func read(b: *Box) -> int = b.n
func go() -> int {
    return read(new Box { n: 8 })
}

Runs `go` → 42

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_AssignedToFieldThenRead   topic: allocation   status: verified
// verified behavior: Test.go(...) == 42

namespace Test
data Inner { v: int }
data Holder { var p: *Inner }
func go() -> int {
    var h = Holder { p: nil }
    h.p = new Inner { v: 42 }
    return h.p.v
}

ILEmitterTests_New__New_BuildListInLoop

allocation runnable verified ×2

Runs `go` → 10

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_BuildListInLoop   topic: allocation   status: verified
// verified behavior: Test.go(...) == 10

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    var head: *Node = nil
    var i = 1
    while i <= 4 {
        head = new Node { value: i, next: head }
        i += 1
    }
    var sum = 0
    var cur = head
    while cur != nil {
        sum += cur.value
        cur = cur.next
    }
    return sum
}

Runs `go` → 43

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_CallsPointerReceiverMethod   topic: allocation   status: verified
// verified behavior: Test.go(...) == 43

namespace Test
data Counter { value: int }
func bump(c: *Counter) { c.value += 1 }
func go() -> int {
    var c = new Counter { value: 42 }
    bump(c)
    return c.value
}

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_ChainedListBuild_LengthFive   topic: allocation   status: verified
// verified behavior: Test.go(...) == 5

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    var head: *Node = nil
    var i = 0
    while i < 5 {
        head = new Node { value: i, next: head }
        i += 1
    }
    var c = 0
    var cur = head
    while cur != nil { c += 1 cur = cur.next }
    return c
}

ILEmitterTests_New__New_Composite_BoolField

allocation runnable verified

Runs `go` → true

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_BoolField   topic: allocation   status: verified
// verified behavior: Test.go(...) == true

namespace Test
data Flag { on: bool }
func go() -> bool {
    let f = new Flag { on: true }
    return f.on
}

ILEmitterTests_New__New_Composite_DoubleField

allocation runnable verified

Runs `go` → 2.5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_DoubleField   topic: allocation   status: verified
// verified behavior: Test.go(...) == 2.5

namespace Test
data Num { v: double }
func go() -> double {
    let n = new Num { v: 2.5 }
    return n.v
}

Runs `go` → 6

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_MutatesThroughPointer   topic: allocation   status: verified
// verified behavior: Test.go(...) == 6

namespace Test
data Counter { value: int }
func go() -> int {
    var c = new Counter { value: 1 }
    c.value += 5
    return c.value
}

Runs `go` → 30

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_NewlineSeparatedFields   topic: allocation   status: verified
// verified behavior: Test.go(...) == 30

namespace Test
data Point { x: int, y: int }
func go() -> int {
    let p = new Point {
        x: 10
        y: 20
    }
    return p.x + p.y
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_ReadsFirstField   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Point { x: int, y: int }
func go() -> int {
    let p = new Point { x: 3, y: 4 }
    return p.x
}

Runs `go` → 4

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_ReadsSecondField   topic: allocation   status: verified
// verified behavior: Test.go(...) == 4

namespace Test
data Point { x: int, y: int }
func go() -> int {
    let p = new Point { x: 3, y: 4 }
    return p.y
}

ILEmitterTests_New__New_Composite_StringField

allocation runnable verified

Runs `go` → "hi"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_StringField   topic: allocation   status: verified
// verified behavior: Test.go(...) == "hi"

namespace Test
data Label { text: string }
func go() -> string {
    let l = new Label { text: "hi" }
    return l.text
}

ILEmitterTests_New__New_Composite_SumsFields

allocation runnable verified

Runs `go` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Composite_SumsFields   topic: allocation   status: verified
// verified behavior: Test.go(...) == 7

namespace Test
data Point { x: int, y: int }
func go() -> int {
    let p = new Point { x: 3, y: 4 }
    return p.x + p.y
}

ILEmitterTests_New__New_DataWithDefaultField

allocation runnable verified

Runs `go` → 8

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_DataWithDefaultField   topic: allocation   status: verified
// verified behavior: Test.go(...) == 8

namespace Test
data Box { n: int }
func twice(b: *Box) -> int = b.n + b.n
func go() -> int { return twice(new Box { n: 4 }) }

ILEmitterTests_New__New_DeepLinkedListSum

allocation runnable verified

Runs `go` → 55

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_DeepLinkedListSum   topic: allocation   status: verified
// verified behavior: Test.go(...) == 55

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    var head: *Node = nil
    var i = 1
    while i <= 10 {
        head = new Node { value: i, next: head }
        i += 1
    }
    var sum = 0
    var cur = head
    while cur != nil { sum += cur.value cur = cur.next }
    return sum
}

Runs `go` → 9

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_ExplicitPointerAnnotation   topic: allocation   status: verified
// verified behavior: Test.go(...) == 9

namespace Test
data Box { n: int }
func go() -> int {
    var b: *Box = new Box { n: 9 }
    return b.n
}

Runs `go` → 50

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_FollowedByMethodCallViaLocal   topic: allocation   status: verified
// verified behavior: Test.go(...) == 50

namespace Test
data Box { n: int }
func scaled(b: *Box) -> int = b.n * 10
func go() -> int {
    let b = new Box { n: 5 }
    return scaled(b)
}

ILEmitterTests_New__New_Generic_Pair_First

allocation runnable verified

Runs `go` → 42

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Generic_Pair_First   topic: allocation   status: verified
// verified behavior: Test.go(...) == 42

namespace Test
data Pair<A, B> { first: A, second: B }
func go() -> int {
    let p = new Pair<int, string> { first: 42, second: "x" }
    return p.first
}

ILEmitterTests_New__New_Generic_Pair_Second

allocation runnable verified

Runs `go` → "hello"

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Generic_Pair_Second   topic: allocation   status: verified
// verified behavior: Test.go(...) == "hello"

namespace Test
data Pair<A, B> { first: A, second: B }
func go() -> string {
    let p = new Pair<int, string> { first: 1, second: "hello" }
    return p.second
}

ILEmitterTests_New__New_Generic_SameTypeArgs

allocation runnable verified

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_Generic_SameTypeArgs   topic: allocation   status: verified
// verified behavior: Test.go(...) == 5

namespace Test
data Pair<A, B> { first: A, second: B }
func go() -> int {
    let p = new Pair<int, int> { first: 2, second: 3 }
    return p.first + p.second
}

ILEmitterTests_New__New_GenericNestedTypeArg

allocation runnable verified

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_GenericNestedTypeArg   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Pair<A, B> { first: A, second: B }
func go() -> int {
    let p = new Pair<int, int> { first: 1, second: 2 }
    return p.first + p.second
}

ILEmitterTests_New__New_InIfBody

allocation runnable verified

Runs `go` → 5

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InIfBody   topic: allocation   status: verified
// verified behavior: Test.go(...) == 5

namespace Test
data Box { n: int }
func go() -> int {
    var b = new Box { n: 0 }
    if true {
        b = new Box { n: 5 }
    }
    return b.n
}

Runs `go` → 11

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InListLiteral_IndexThenMutate   topic: allocation   status: verified
// verified behavior: Test.go(...) == 11

namespace Test
data Box { n: int }
func go() -> int {
    let xs = [new Box { n: 10 }, new Box { n: 20 }]
    xs[0].n += 1
    return xs[0].n
}

ILEmitterTests_New__New_InListLiteral_ThenIndex

allocation runnable verified ×3

Runs `go` → 20

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InListLiteral_ThenIndex   topic: allocation   status: verified
// verified behavior: Test.go(...) == 20

namespace Test
data Box { n: int }
func go() -> int {
    let xs = [new Box { n: 10 }, new Box { n: 20 }]
    return xs[1].n
}

ILEmitterTests_New__New_InMatchArm

allocation runnable verified

Runs `go` → 7

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InMatchArm   topic: allocation   status: verified
// verified behavior: Test.go(...) == 7

namespace Test
data Box { n: int }
choice Sel { a, b }
func go() -> int {
    let s = Sel.a()
    var box = new Box { n: 0 }
    match s {
        .a { box = new Box { n: 7 } }
        .b { box = new Box { n: 9 } }
    }
    return box.n
}

ILEmitterTests_New__New_InStaticFuncBody

allocation runnable verified

Runs `go` → 6

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InStaticFuncBody   topic: allocation   status: verified
// verified behavior: Test.go(...) == 6

namespace Test
data Box { n: int }
static func Maker {
    func build(v: int) -> *Box = new Box { n: v }
}
func go() -> int {
    let b = Maker.build(6)
    return b.n
}

ILEmitterTests_New__New_InTernaryBranch

allocation runnable verified

Runs `go` → 2

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InTernaryBranch   topic: allocation   status: verified
// verified behavior: Test.go(...) == 2

namespace Test
data Box { n: int }
func go() -> int {
    let cond = false
    let b = cond ? new Box { n: 1 } : new Box { n: 2 }
    return b.n
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_InWhileConditionArgument   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Box { n: int }
func alive(b: *Box) -> bool = b.n > 0
func go() -> int {
    var count = 0
    var n = 3
    while alive(new Box { n: n }) {
        count += 1
        n -= 1
    }
    return count
}

Runs `go` → 10

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_LinkedList_NilTailTerminates   topic: allocation   status: verified
// verified behavior: Test.go(...) == 10

namespace Test
data Node { value: int, next: *Node }
func go() -> int {
    let only = new Node { value: 10, next: nil }
    return only.value
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_LinkedList_PrependReturnsPointer   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Node { value: int, next: *Node }
func prepend(head: *Node, value: int) -> *Node {
    return new Node { value: value, next: head }
}
func go() -> int {
    var head: *Node = nil
    head = prepend(head, 10)
    head = prepend(head, 20)
    head = prepend(head, 30)
    var count = 0
    var cur = head
    while cur != nil {
        count += 1
        cur = cur.next
    }
    return count
}

ILEmitterTests_New__New_LinkedList_SumsThree

allocation runnable verified

Runs `go` → 6

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_LinkedList_SumsThree   topic: allocation   status: verified
// verified behavior: Test.go(...) == 6

namespace Test
data Node { value: int, next: *Node }
func go() -> 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
}

Runs `go` → 3

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_MultipleInOneExpression   topic: allocation   status: verified
// verified behavior: Test.go(...) == 3

namespace Test
data Box { n: int }
func add(a: *Box, b: *Box) -> int = a.n + b.n
func go() -> int { return add(new Box { n: 1 }, new Box { n: 2 }) }

ILEmitterTests_New__New_MutateLinkedListNode

allocation runnable verified

Runs `go` → 99

// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_New.cs::New_MutateLinkedListNode   topic: allocation   status: verified
// verified behavior: Test.go(...) == 99

namespace Test
data Node { var value: int, next: *Node }
func go() -> int {
    var head = new Node { value: 1, next: nil }
    head.value = 99
    return head.value
}