From cc7df3ddd771c4cdeaf0d0ff244a64db3249f2de Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 13 Apr 2024 00:38:03 +0800 Subject: [PATCH 1/2] T.method support alias --- codebuild.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/codebuild.go b/codebuild.go index a4cae9f..b242358 100644 --- a/codebuild.go +++ b/codebuild.go @@ -1526,11 +1526,14 @@ 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 From aaeebe6009e04ff7e1fc5f0fd5598b421db0ddde Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 13 Apr 2024 01:04:11 +0800 Subject: [PATCH 2/2] aliasNameOf bugfix: don't change flag = memberFlagMethodToFunc --- codebuild.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codebuild.go b/codebuild.go index b242358..7c3bc9c 100644 --- a/codebuild.go +++ b/codebuild.go @@ -1538,7 +1538,9 @@ func aliasNameOf(name string, flag MemberFlag) (string, MemberFlag) { 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 } @@ -1559,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)