Skip to content

Commit 7ed7e83

Browse files
committed
parser 禁止类型别名
1 parent 06c3e74 commit 7ed7e83

File tree

8 files changed

+6
-17
lines changed

8 files changed

+6
-17
lines changed

internal/ast/ast.go

-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ type (
790790
Name *Ident // type name
791791
TypeParams *FieldList // type parameters; or nil
792792
ColonPos token.Pos // position of ":" operator (token.NoPos if there is no ":")
793-
Assign token.Pos // position of '=', if any
794793
Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
795794
Comment *CommentGroup // line comments; or nil
796795
}

internal/frontend/wz/parser/parser.go

-6
Original file line numberDiff line numberDiff line change
@@ -2432,9 +2432,6 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
24322432
if p.tok == token.COLON {
24332433
spec.ColonPos = p.pos
24342434
p.next()
2435-
} else if p.tok == token.ASSIGN {
2436-
spec.Assign = p.pos
2437-
p.next()
24382435
}
24392436
spec.Type = p.parseType()
24402437
p.expectSemi() // call before accessing p.linecomment
@@ -2890,9 +2887,6 @@ func (p *parser) 解析类型定义() *ast.GenDecl {
28902887
if p.tok == token.COLON {
28912888
spec.ColonPos = p.pos
28922889
p.next()
2893-
} else if p.tok == token.ASSIGN {
2894-
spec.Assign = p.pos
2895-
p.next()
28962890
}
28972891
// spec.Type = p.parseType()
28982892

internal/parser/parser.go

-3
Original file line numberDiff line numberDiff line change
@@ -2443,9 +2443,6 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
24432443
if p.tok == token.COLON {
24442444
spec.ColonPos = p.pos
24452445
p.next()
2446-
} else if p.tok == token.ASSIGN {
2447-
spec.Assign = p.pos
2448-
p.next()
24492446
}
24502447
spec.Type = p.parseType()
24512448
p.expectSemi() // call before accessing p.linecomment

internal/printer/nodes.go

-3
Original file line numberDiff line numberDiff line change
@@ -1571,9 +1571,6 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
15711571
} else {
15721572
p.print(vtab)
15731573
}
1574-
if s.Assign.IsValid() {
1575-
p.print(token.ASSIGN, blank)
1576-
}
15771574
p.expr(s.Type)
15781575
p.setComment(s.Comment)
15791576

internal/types/decl.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func (check *Checker) declare(scope *Scope, id *ast.Ident, obj Object, pos token
3939

4040
// pathString returns a string of the form a->b-> ... ->g for a path [a, b, ... g].
4141
// TODO(gri) remove once we don't need the old cycle detection (explicitly passed
42-
// []*TypeName path) anymore
42+
//
43+
// []*TypeName path) anymore
4344
func pathString(path []*TypeName) string {
4445
var s string
4546
for i, p := range path {
@@ -682,7 +683,7 @@ func (check *Checker) declStmt(decl ast.Decl) {
682683
check.declare(check.scope, s.Name, obj, scopePos)
683684
// mark and unmark type before calling typeDecl; its type is still nil (see Checker.objDecl)
684685
obj.setColor(grey + color(check.push(obj)))
685-
check.typeDecl(obj, s.Type, nil, s.Assign.IsValid())
686+
check.typeDecl(obj, s.Type, nil, false)
686687
check.pop().setColor(black)
687688
default:
688689
check.invalidAST(s.Pos(), "const, type, or var declaration expected")

internal/types/resolver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (check *Checker) collectObjects() {
404404
case *ast.TypeSpec:
405405
obj := NewTypeName(s.Name.Pos(), pkg, s.Name.Name, nil)
406406
obj.setNode(s)
407-
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: s.Assign.IsValid()})
407+
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, typ: s.Type, alias: false})
408408

409409
if s.Doc == nil {
410410
if d.Lparen == token.NoPos && d.Doc != nil {

waroot/changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 版本日志
22

33
- (dev)
4+
- 禁止类型别名
45
- v0.9.0 (2023-12-15) MVP
56
- 增加胶水代码定义特性
67
- 添加 js、js/cancas 标准库

waroot/src/math/bits/bits_test.wa

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const DeBruijn64 = deBruijn64
77

8-
type entry = struct {
8+
type entry struct {
99
nlz, ntz, pop: int
1010
}
1111

0 commit comments

Comments
 (0)