Files
pplus-library/mojo/probes/list-literal-into-place.mojo
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

37 lines
956 B
Mojo

# probe: a list in brackets assigned to a List variable, a struct field, a List element or a Dict entry: is it a List (append works), and do its items take the element type?
@fieldwise_init
struct Box(Copyable, Movable):
var items: List[Int]
var weights: List[Float64]
def main() raises:
var a = List[Int]()
a = [1, 2]
a.append(3)
print(a)
var f = List[Float64]()
f = [1, 2]
f.append(3)
print(f)
var b = Box(List[Int](), List[Float64]())
b.items = [4, 5]
b.items.append(6)
b.weights = [7, 8]
print(b.items, b.weights)
var g: List[List[Int]] = [[1], [2]]
g[0] = [9, 9]
g[0].append(10)
g.append([11])
print(g)
var d = Dict[String, List[Int]]()
d["k"] = [1]
d["k"].append(2)
print(d["k"])
var h: Dict[String, List[Float64]] = {"x": [1, 2]}
h["x"].append(3)
print(h["x"])
var c = Box([1], [2])
c.items.append(3)
print(c.items, c.weights)