Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/check/synth/phase/extract/synthesizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func (s *Synthesizer) synthIdentCore(ex *ast.IdentExpr, p cfg.Point, sc *scope.S
}
}
}
if sc != nil {
if t, ok := sc.LookupType(ex.Value); ok && t != nil {
return typ.NewMeta(t)
}
}
return typ.Unknown
}

Expand Down Expand Up @@ -440,6 +445,16 @@ fallback:
}
}

// Type names used in expression context (e.g. Config = Config in a return
// table) resolve to a Meta type wrapping the declared type. This enables
// type values to flow through module exports as first-class values,
// supporting patterns like mylib.Config:is(data) across module boundaries.
if sc != nil {
if t, ok := sc.LookupType(ex.Value); ok && t != nil {
return typ.NewMeta(t)
}
}

return typ.Unknown
}

Expand Down
570 changes: 289 additions & 281 deletions compiler/parse/parser.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions compiler/parse/parser.go.y
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@ primarytypeexpr:
$$ = &ast.FunctionTypeExpr{Params: $2, Returns: $6}
$$.SetPosFromToken($1.Pos)
} |
'(' funcparamlist ')' TArrow '(' ')' {
$$ = &ast.FunctionTypeExpr{Params: $2, Returns: []ast.TypeExpr{}}
$$.SetPosFromToken($1.Pos)
} |
'(' funcparamlist ')' TArrow typeexpr {
$$ = &ast.FunctionTypeExpr{Params: $2, Returns: []ast.TypeExpr{$5}}
$$.SetPosFromToken($1.Pos)
Expand Down
38 changes: 38 additions & 0 deletions compiler/parse/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1942,3 +1942,41 @@ func TestParseGenericFunctionExpr(t *testing.T) {
t.Errorf("TypeParams[0].Name = %q, want 'T'", fn.TypeParams[0].Name)
}
}

func TestParseVoidReturnInRecordField(t *testing.T) {
tests := []struct {
name string
input string
}{
{
name: "named params void return with comma",
input: `type C = {f: (self: C) -> (),}`,
},
{
name: "named params void return no comma",
input: `type C = {f: (self: C) -> ()}`,
},
{
name: "named params void return multiline",
input: "type C = {\n f: (self: C) -> (),\n g: (self: C, x: number) -> ()\n}",
},
{
name: "multiple named params void return",
input: `type C = {f: (a: number, b: string) -> ()}`,
},
{
name: "no params void return",
input: `type C = {f: () -> ()}`,
},
// Parenthesized single return like (number) is ambiguous with grouping
// and handled separately via the typeexprlist2 rule for 2+ returns.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := ParseString(tt.input, "test")
if err != nil {
t.Errorf("expected no parse error, got: %v", err)
}
})
}
}
Loading