Skip to content

Commit dbd4395

Browse files
committed
Replace array[T]/map[K,V] syntax with []T/map[K]V
- SliceType: `[]T` replaces `array[T]` everywhere types are valid — struct fields, function params, return types, typed var decls, named type declarations, interface methods, variant arms - MapType: `map[K]V` replaces `map[K,V]` (Go-style, no comma) - Bare `array` and bare `map` in type positions are now compile errors (UnexpectedToken); use `[]any`/`map[K]V` instead - `type JobQueue []Job` and `type Scores map[string]int` work as named types - Update all spec files, fail specs, and simlab playground files - Add fail/099 and fail/100 to document the bare-keyword errors
1 parent 17d82d7 commit dbd4395

17 files changed

Lines changed: 425 additions & 67 deletions

examples/spec/014_struct_typed_fields.gengo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
std := import("std")
22

33
type Addr struct { city string }
4-
type User struct { id int, name string, active bool, score float, tags array, meta map, addr Addr }
4+
type User struct { id int, name string, active bool, score float, tags []int, meta map[string]int, addr Addr }
55

66
u := User{
77
id: 7,

examples/spec/063_for_in_break_continue.gengo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
std := import("std")
22

3-
func sum_until_sentinel(arr array) int {
3+
func sum_until_sentinel(arr []int) int {
44
acc := 0
55
for x in arr {
66
if x == 99 { break }
@@ -9,7 +9,7 @@ func sum_until_sentinel(arr array) int {
99
return acc
1010
}
1111

12-
func sum_skip_zero(arr array) int {
12+
func sum_skip_zero(arr []int) int {
1313
acc := 0
1414
for x in arr {
1515
if x == 0 { continue }
@@ -18,7 +18,7 @@ func sum_skip_zero(arr array) int {
1818
return acc
1919
}
2020

21-
func count_kv_before_sentinel(m map) int {
21+
func count_kv_before_sentinel(m map[string]int) int {
2222
count := 0
2323
for k, v in m {
2424
if k == "stop" { break }
@@ -55,7 +55,7 @@ func sum_cfor_with_continue(n int) int {
5555
return s
5656
}
5757

58-
func sum_with_local_in_break_block(arr array) int {
58+
func sum_with_local_in_break_block(arr []int) int {
5959
acc := 0
6060
for x in arr {
6161
if x == 99 {
@@ -68,7 +68,7 @@ func sum_with_local_in_break_block(arr array) int {
6868
return acc
6969
}
7070

71-
func sum_body_local(arr array) int {
71+
func sum_body_local(arr []int) int {
7272
acc := 0
7373
for x in arr {
7474
doubled := x * 2

examples/spec/068_typed_decl_coerce_assert.gengo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ std.io.println(r)
1717
r2 rune = `Z`
1818
std.io.println(r2)
1919

20-
// array: enforces type
21-
a array = [1, 2, 3]
20+
// []T: enforces sequence type
21+
a []int = [1, 2, 3]
2222
std.io.println(std.core.len(a))
2323

24-
// map: enforces type
25-
m map = {x: 1, y: 2}
24+
// map[K]V: enforces map type
25+
m map[string]int = {x: 1, y: 2}
2626
std.io.println(std.core.len(m))
2727

2828
// error: enforces type

examples/spec/078_typed_collections.gengo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
std := import("std")
22

33
type Point struct { x float, y float }
4-
type Points array[Point]
5-
type Index map[string, Point]
4+
type Points []Point
5+
type Index map[string]Point
66

77
// Construct named collection types
88
pts := Points([Point{x: 1.0, y: 2.0}, Point{x: 3.0, y: 4.0}])
@@ -26,7 +26,7 @@ idx := Index({"origin": Point{x: 0.0, y: 0.0}})
2626
std.io.println(idx["origin"].x)
2727

2828
// Anonymous typed annotation in function param
29-
func sumX(ps array[Point]) float {
29+
func sumX(ps []Point) float {
3030
total float = 0.0
3131
for p in ps {
3232
total += p.x
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
x array = "not an array"
1+
x []any = "not an array"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
x map = [1, 2, 3]
1+
x map[string]any = [1, 2, 3]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
type Point struct { x float, y float }
2-
type Points array[Point]
2+
type Points []Point
33

44
_ := Points([Point{x: 1.0, y: 2.0}, "not a point"])

examples/spec/fail/086_typed_array_param_wrong.gengo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type Point struct { x float, y float }
22

3-
func sumX(ps array[Point]) float {
3+
func sumX(ps []Point) float {
44
return 0.0
55
}
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
std := import("std")
22

33
type Point struct { x float, y float }
4-
type Points array[Point]
4+
type Points []Point
55

66
pts := Points([Point{x: 1.0, y: 2.0}])
77
_ := std.core.append(pts, "not a point")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
type Point struct { x float, y float }
2-
type Index map[string, Point]
2+
type Index map[string]Point
33

44
_ := Index({"a": Point{x: 1.0, y: 2.0}, "b": 42})

0 commit comments

Comments
 (0)