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

cmd/go2go: gofmt doesn't work #41079

Closed
YoshikiShibata opened this issue Aug 27, 2020 · 5 comments
Closed

cmd/go2go: gofmt doesn't work #41079

YoshikiShibata opened this issue Aug 27, 2020 · 5 comments

Comments

@YoshikiShibata
Copy link

@YoshikiShibata YoshikiShibata commented Aug 27, 2020

go2 version:

$ git rev-parse HEAD
af1adc5d8ce8125ae953359402989eb8c14988c5

Thanks for fixing gofmt, but another problem.

I declare Builder as following:

// Builder is a mutable builder for a Stream. This allows the creation of a
// Stream by generating elements individually and adding them to the Builder.
type Builder[type T any] struct {
}

// Add adds an element to the stream being built.
func (b *Builder[T]) Add(t T) {
    panic("Not Implemented Yet")
}

With this declaration, I can compile and run the following code:

func TestBuilder(t *testing.T) {
    var builder Builder[int]

    for i := 0; i < 100; i++ {
        builder.Add(i)
    }
}

However, after gofmt which deletes type from the Builder declaration as following:

type Builder[T any] struct {
}

Then the testing code above will not be compiled:

builder_test.go2:6:21: expected ';', found '['

Line 6 is var builder Builder[int] in the above testing code.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 27, 2020

I can't recreate this problem at dev.go2go revision af1adc5. Can you a complete test case? Thanks.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 27, 2020
@YoshikiShibata YoshikiShibata changed the title cmd/go2go: cannot instantiate an parameterized type cmd/go2go: gofmt doesn't work Aug 27, 2020
@YoshikiShibata
Copy link
Author

@YoshikiShibata YoshikiShibata commented Aug 28, 2020

@ianlancetaylor

I changed the subject because the problem happens with gofmt.

If I put everything into one .go2 file, there is no problem. But,

builder.go2:

package main

type Builder[T any] struct {
    built bool
    data  []T 
}

func (b *Builder[T]) Add(t T) {
    if b.built {
        panic("Already built state")
    }   
    b.data = append(b.data, t)
}

builder_test.go2:

package main

import "testing"

func TestBuilder(t *testing.T) {
    var builder Builder[int]

    for i := 0; i < 100; i++ {
        builder.Add(i)
    }   
}

Then

$ gofmt -w builder_test.go2
builder_test.go2:6:21: expected ';', found '['
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 28, 2020

Change https://golang.org/cl/251278 mentions this issue: [dev.go2go] cmd/gofmt: pass UnifiedParamLists to parser

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 28, 2020

Thanks, this should be fixed now on the dev.go2go branch.

gopherbot pushed a commit that referenced this issue Aug 28, 2020
Fixes #41079

Change-Id: I781c5c681c66712ed2ac0112dd44fa8793845978
Reviewed-on: https://go-review.googlesource.com/c/go/+/251278
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@YoshikiShibata
Copy link
Author

@YoshikiShibata YoshikiShibata commented Aug 28, 2020

@ianlancetaylor Thanks for the fix. It works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.