data — examples
← all topics · 199 examples · page 4 of 4 · raw source ↓
Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: MixedLanguageTests.cs::Esharp_Data_Type_Used_From_Csharp topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
pub data Point { x: int, y: int }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::BoxingDiag_NoWarn_RefData topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IWidget {
func render() -> string
}
ref data Button : IWidget {
label: string
}
func render(b: Button) -> string {
return b.label
}
func test() -> string {
let w: IWidget = Button { label: "ok" }
return w.render()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Classifies_Nested_Struct_Within_Threshold topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Lines
data Vec2 {
x: float
y: float
}
data Line {
a: Vec2
b: Vec2
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Classifies_Oversized_As_Struct topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Big
data Big {
a: decimal
b: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Classifies_RefData_As_Class topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Cfg
ref data Config {
timeout: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Classifies_RefField_As_Struct topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Wrap
data Wrapper {
name: string
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Classifies_Small_ValueType_As_Struct topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Geo
data Point {
x: int
y: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::ExplicitConformance_Satisfied topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IRenderable {
func render() -> string
}
ref data Button : IRenderable {
label: string
}
func render(b: Button) -> string {
return b.label
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::MultiFile_CrossFile_Instance_Method_Promotion topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Types
data Counter {
value: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::MultiFile_CrossFile_Protocol_Satisfaction topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Proto
interface IDescribable {
func describe() -> string
}
data Widget : IDescribable {
label: string
}
func describe(w: Widget) -> string {
return w.label
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::MultiFile_CrossFile_Type_Reference topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Types
data Point {
x: int
y: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Attribute_On_RefData topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
[Route("/api/users")]
[Authorize]
ref data UserController {
path: string
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Attribute_With_Arguments topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
[MaxLength(100)]
ref data Config {
name: string
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Data_With_External_Interface topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace IO
data FileHandle : IDisposable {
path: string
}
func Dispose(h: FileHandle) {
Console.WriteLine("closed")
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Derive_Debug topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Dbg
derive debug
data Color {
r: int
g: int
b: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Derive_Equality topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Eq
derive equality
data Point {
x: int
y: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Generic_Data topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Gen
data Pair<A, B> {
first: A
second: B
}
func makePair<A, B>(a: A, b: B) -> Pair<A, B> {
return Pair<A, B> { first: a, second: b }
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Init_Constructor topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
ref data Connection {
host: string
port: int
init(h: string, p: int) {
host = h
port = p
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_Nullable_Return_Type topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data User {
name: string
}
func find(id: int) -> User? {
return nil
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::Transpiles_ValueEmbedding topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Base {
var x: int
var y: int
}
data Widget {
Base
label: string
}
func getX() -> int {
var w = Widget { x: 10, y: 20, label: "test" }
return w.x
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::VirtualDispatch_ProtocolTypedParameter topic: data status: verified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IWidget {
func render() -> string
}
ref data Button : IWidget {
label: string
}
func render(b: Button) -> string {
return b.label
}
func display(w: IWidget) -> string {
return w.render()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::HeapAllocAttribute_OnRefData_Errors topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
[HeapAlloc]
ref data Conn {
host: string
port: int
}Rejected at compile time: ES3012
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::InitBlock_OnData_Errors topic: data status: unverified
// verified behavior: reports diagnostic ES3012
namespace Test
data Point {
x: int
y: int
init(px: int, py: int) {
self.x = px
self.y = py
}
}Rejected at compile time: ES3012
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::InitBlock_OnRefData_Ok topic: data status: unverified
// verified behavior: reports diagnostic ES3012
namespace Test
ref data Point {
x: int
y: int
init(px: int, py: int) {
self.x = px
self.y = py
}
}Rejected at compile time: ES3012
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::PositionalForm_OnData_StillWorks topic: data status: unverified
// verified behavior: reports diagnostic ES3012
namespace Test
data Vec2(x: int, y: int)
func main() {
let v = Vec2(3, 4)
}Rejected at compile time: ES2002
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::RecursiveField_ListOfPointer_Ok topic: data status: unverified
// verified behavior: reports diagnostic ES2002
namespace Test
data Tree {
value: int
children: List<*Tree>
}Rejected at compile time: ES2002
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::RecursiveField_PointerForm_Ok topic: data status: unverified
// verified behavior: reports diagnostic ES2002
namespace Test
data Node {
value: int
next: *Node
}Rejected at compile time: ES2002
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::RecursiveField_RefDataAllowsSelfReference topic: data status: unverified
// verified behavior: reports diagnostic ES2002
namespace Test
ref data Node {
value: int
next: Node
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::StackAllocAndHeapAlloc_Together_Errors topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
[StackAlloc]
[HeapAlloc]
data Point {
x: int
y: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: DataContractTests.cs::StackAllocAttribute_OnRefData_Errors topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
[StackAlloc]
ref data Conn {
host: string
port: int
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: EmitterStressTests.cs::InterfaceImplWithLambdaArgs topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace T
ref data Plugin {
name: string
init() { self.name = "test" }
pub func Name() -> string = self.name
pub func Run(app: WebApplication) {
app.MapGet("/api/test", func(q: string) -> IResult {
return Results.Json(q ?? "default")
})
app.MapGet("/api/ping", func() -> IResult = Results.Json("pong"))
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: EmitterStressTests.cs::Parse_ConstructorCallWith6ArgsInForLoop topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace T
data Item(a: string, b: string, c: string, d: DateTimeOffset, e: string, f: string)
func run(synd: object, feed: object) {
var items = List<Item>()
for entry in synd.Items {
let link = entry.Links.Count > 0 ? entry.Links[0].Uri.ToString() : ""
let summary = entry.Summary?.Text ?? ""
let pub = entry.PublishDate != DateTimeOffset.MinValue ? entry.PublishDate : entry.LastUpdatedTime
items.Add(Item(entry.Title.Text, link, feed.name, pub, summary, feed.category))
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::LetField_AssignmentOutsideInit_ReportsError topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
data Point {
let x: int
y: int
}
func bad() -> int {
var p = Point { x: 1, y: 2 }
p.x = 99
return p.x
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Parse_ExprBodiedWithLock topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
ref data Foo {
x: int
lock: object
init() {
self.x = 0
self.lock = object()
}
func getX() -> int = self.x
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Parse_InterfaceImplementation topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace T
ref data MyPlugin : IPlugin {
init() { }
pub func Name() -> string = "test"
pub func Run(app: WebApplication) {
app.MapGet("/api/test", func(q: string) -> IResult {
return Results.Json(q ?? "")
})
app.MapGet("/api/ping", func() -> IResult = Results.Json("pong"))
}
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::Parse_RefDataWithMultipleMethods topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace T
ref data Svc {
items: List<string>
obj: object
init() {
self.items = List<string>()
self.obj = object()
}
func start() { self.items.Add("a") }
func stop() { self.items.Clear() }
func query(filter: string) -> List<string> { return self.items }
func count() -> int = self.items.Count
func addItem(s: string) = self.items.Add(s)
}Rejected at compile time: ES2001
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StructPromotion_LargeStruct_SilentlyPromotesToClass topic: data status: unverified
// verified behavior: reports diagnostic ES2001
namespace Test
data Big {
a: double
b: double
c: double
d: double
e: double
f: double
g: double
h: double
i: double
}Rejected at compile time: ES2001
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StructPromotion_ManyRefFields_SilentlyPromotesToClass topic: data status: unverified
// verified behavior: reports diagnostic ES2001
namespace Test
data Refs {
a: string
b: string
c: string
d: int
}Rejected at compile time: ES2001
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StructPromotion_RefData_NoWarning topic: data status: unverified
// verified behavior: reports diagnostic ES2001
namespace Test
ref data Big {
a: double
b: double
c: double
d: double
e: double
f: double
g: double
h: double
i: double
}Rejected at compile time: ES2001
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::StructPromotion_StoredInCollection_SilentlyPromotesToClass topic: data status: unverified
// verified behavior: reports diagnostic ES2001
namespace Test
data Item {
a: double
b: double
c: double
d: double
e: double
}
data Container {
items: List<Item>
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests.cs::With_OnRefData_ReportsError topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
ref data Node {
value: int
}
func run() -> int {
let n = Node { value: 1 }
let m = n with { value: 2 }
return m.value
}Rejected at compile time: ES2150
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Coverage_Adversarial.cs::Ns_BareCrossNamespace_WithoutUsing_IsError topic: data status: unverified
// verified behavior: reports diagnostic ES2150
namespace Lib
data Vec { x: int }Runs `go` → 9
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_GenericConformance topic: data status: unverified
// verified behavior: Test.go(...) == 9
generic value data implementing an interface (promoted generic-method self-param) not yet supportedCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_ParamTypeMismatch_IsError topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IAdder { func add(x: int) -> int }
data Calc : IAdder { base: int }
func add(c: Calc, x: string) -> int = c.baseCompiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Added_UndeclaredStructuralMatch_IsNotConformance topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface ISized { func size() -> int }
data Crate { items: int }
func size(c: Crate) -> int = c.items
func measure(s: ISized) -> int = s.size()
func go() -> int { let c = Crate { items: 3 } return measure(c) }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Declared_ParamTypeMismatch_IsError topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IAdder { func add(n: int) -> int }
data Box : IAdder { v: int }
func add(b: Box, n: string) -> int { return b.v }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: ILEmitterTests_Nominal.cs::Declared_ReturnTypeMismatch_IsError topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface ISized { func size() -> int }
data Crate : ISized { items: int }
func size(c: Crate) -> string { return "x" }Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::BoxingDiag_Warns_ValueType_As_Protocol topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IWidget {
func render() -> string
}
data SmallWidget {
label: string
}
func render(w: SmallWidget) -> string {
return w.label
}
func test() -> string {
let w: IWidget = SmallWidget { label: "hi" }
return w.render()
}Compiles
// E# — a verified example from the E# language corpus (CLR language; .es, not ECMAScript).
// provenance: TranspilerTests.cs::ExplicitConformance_Missing_Method_Reports_Error topic: data status: unverified
// compiles cleanly (no auto-run claim was extracted)
namespace Test
interface IRenderable {
func render() -> string
}
ref data Button : IRenderable {
label: string
}