Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: missing Info.Types for *ast.FuncType #70908

Open
adonovan opened this issue Dec 18, 2024 · 2 comments
Open

go/types: missing Info.Types for *ast.FuncType #70908

adonovan opened this issue Dec 18, 2024 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@adonovan
Copy link
Member

In this program, types.Info.Types records no type for f's ast.FuncType node. I think it should:

package p

func f() (int, string) {
    return 0, "" 
}
Screenshot 2024-12-18 at 1 29 13 PM

@madelinekalil

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@Agent-Hellboy
Copy link

Agent-Hellboy commented Dec 23, 2024

Hi @adonovan,

I’d like to work on this if @madelinekalil approve the issue. I’ve recently added a PR on a mini parser for go.mod, and the Go codebase looks clean and approachable. I am particularly interested in the parser, AST, and type-checking stages, and I want to contribute to these areas as they seem beginner-friendly and a great way to start learning a language's type system through hands-on experience.

patch:

diff --git a/src/go/types/signature.go b/src/go/types/signature.go
index 681eb85fd7..590e0a982b 100644
--- a/src/go/types/signature.go
+++ b/src/go/types/signature.go
@@ -106,12 +106,18 @@ func (s *Signature) String() string   { return TypeString(s, nil) }
 
 // funcType type-checks a function or method type.
 func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast.FuncType) {
        check.openScope(ftyp, "function")
        check.scope.isFunc = true
        check.recordScope(ftyp, check.scope)
        sig.scope = check.scope
        defer check.closeScope()
 
+       if check.Info.Types != nil {
+               check.recordTypeAndValue(ftyp, typexpr, sig, nil)
+       }
+
        // collect method receiver, if any
        var recv *Var
        var rparams *TypeParamList

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants