Skip to content

Commit

Permalink
Merge pull request #425 from xushiwei/q
Browse files Browse the repository at this point in the history
T.method support alias
  • Loading branch information
xushiwei authored Apr 12, 2024
2 parents 25d8a4f + aaeebe6 commit 4d7d84d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,16 +1526,21 @@ const (
MemberFlagRef MemberFlag = -1

// private state
memberFlagMethodToFunc MemberFlag = -2
memberFlagMethodToFunc MemberFlag = 0x80
)

func aliasNameOf(name string, flag MemberFlag) (string, MemberFlag) {
// flag > 0: (flag == MemberFlagMethodAlias || flag == MemberFlagAutoProperty)
// flag > 0 means:
// flag == MemberFlagMethodAlias ||
// flag == MemberFlagAutoProperty ||
// flag == memberFlagMethodToFunc
if flag > 0 && name != "" {
if c := name[0]; c >= 'a' && c <= 'z' {
return string(rune(c)+('A'-'a')) + name[1:], flag
}
flag = MemberFlagVal
if flag != memberFlagMethodToFunc {
flag = MemberFlagVal
}
}
return "", flag
}
Expand All @@ -1556,12 +1561,13 @@ func (p *CodeBuilder) Member(name string, flag MemberFlag, src ...ast.Node) (kin
if flag == MemberFlagRef {
kind = p.refMember(at, name, arg.Val, srcExpr)
} else {
t, isType := at.(*TypeType)
var aliasName string
var t, isType = at.(*TypeType)
if isType { // (T).method or (*T).method
at = t.Type()
flag = memberFlagMethodToFunc
}
aliasName, flag := aliasNameOf(name, flag)
aliasName, flag = aliasNameOf(name, flag)
kind = p.findMember(at, name, aliasName, flag, arg, srcExpr)
if isType && kind != MemberMethod {
code, pos := p.loadExpr(srcExpr)
Expand Down

0 comments on commit 4d7d84d

Please sign in to comment.