Skip to content

Commit 218e24f

Browse files
authored
checker,parser,ast: make type MyBuilder = strings.Builder work (part 1); add mod fields to ast.SumTypeDecl and ast.AliasTypeDecl (#25943)
1 parent c910d25 commit 218e24f

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎cmd/tools/vast/vast.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ fn (t Tree) alias_type_decl(node ast.AliasTypeDecl) &Node {
873873
mut obj := create_object()
874874
obj.add_terse('ast_type', t.string_node('AliasTypeDecl'))
875875
obj.add_terse('name', t.string_node(node.name))
876+
obj.add_terse('mod', t.string_node(node.mod))
876877
obj.add_terse('typ', t.type_node(node.typ))
877878
obj.add_terse('parent_type', t.type_node(node.parent_type))
878879
obj.add_terse('is_pub', t.bool_node(node.is_pub))
@@ -885,6 +886,7 @@ fn (t Tree) sum_type_decl(node ast.SumTypeDecl) &Node {
885886
mut obj := create_object()
886887
obj.add_terse('ast_type', t.string_node('SumTypeDecl'))
887888
obj.add_terse('name', t.string_node(node.name))
889+
obj.add_terse('mod', t.string_node(node.mod))
888890
obj.add_terse('is_pub', t.bool_node(node.is_pub))
889891
obj.add('pos', t.pos(node.pos))
890892
obj.add_terse('typ', t.type_node(node.typ))

‎vlib/v/ast/ast.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,7 @@ pub mut:
15081508
pub struct AliasTypeDecl {
15091509
pub:
15101510
name string
1511+
mod string
15111512
is_pub bool
15121513
typ Type
15131514
pos token.Pos
@@ -1523,6 +1524,7 @@ pub mut:
15231524
pub struct SumTypeDecl {
15241525
pub:
15251526
name string
1527+
mod string
15261528
is_pub bool
15271529
pos token.Pos
15281530
name_pos token.Pos

‎vlib/v/checker/checker.v‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,10 @@ fn (mut c Checker) alias_type_decl(mut node ast.AliasTypeDecl) {
618618
}
619619
.alias {
620620
orig_sym := c.table.sym((parent_typ_sym.info as ast.Alias).parent_type)
621-
if !node.name.starts_with('C.') {
621+
if !node.name.starts_with('C.')
622+
&& parent_typ_sym.name !in ['strings.Builder', 'StringBuilder', 'builtin.StringBuilder'] {
623+
// TODO: remove the whole check, or at least the need for special casing `strings.Builder` and `StringBuilder` here
624+
// after more testing and bootstrapping of the strings.Builder -> builtin.StringBuilder change
622625
c.error('type `${parent_typ_sym.str()}` is an alias, use the original alias type `${orig_sym.name}` instead',
623626
node.type_pos)
624627
}

‎vlib/v/parser/parser.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
30073007
}
30083008
node := ast.SumTypeDecl{
30093009
name: name
3010+
mod: p.mod
30103011
typ: typ
30113012
is_pub: is_pub
30123013
variants: sum_variants
@@ -3072,6 +3073,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
30723073
p.attrs = []
30733074
alias_type_decl := ast.AliasTypeDecl{
30743075
name: name
3076+
mod: p.mod
30753077
is_pub: is_pub
30763078
typ: idx
30773079
parent_type: parent_type

0 commit comments

Comments
 (0)