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/compile: improve error message for invalid use of interface with type constraints #50837

Closed
virtuald opened this issue Jan 26, 2022 · 3 comments
Assignees
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@virtuald
Copy link

What did you do?

https://gotipplay.golang.org/p/K_OPRyt5aJo

package main

type C interface {
	~int
	Fn()
}

func UseInterface(c C) {}

type Foo struct {
	I C
}

What did you expect to see?

./prog.go:8:21: interface with type constraints used as function parameter
./prog.go:11:4: interface with type constraints cannot be used as field

What did you see instead?

./prog.go:8:21: interface contains type constraints
./prog.go:11:4: interface contains type constraints
@ianlancetaylor ianlancetaylor changed the title compiler?: Improve interface with type constraint compilation error cmd/compile: improve error message for invalid use of interface with type constraints Jan 26, 2022
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 26, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jan 26, 2022
@ianlancetaylor
Copy link
Contributor

CC @griesemer

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 27, 2022
@griesemer
Copy link
Contributor

griesemer commented Jan 27, 2022

The checker.varType function needs a context string so that it can report a context-aware error. Straight-forward to fix, needs some Fingerspitzengefühl for good error messages.

@griesemer griesemer self-assigned this Jan 27, 2022
@griesemer
Copy link
Contributor

This reports now:

./prog.go:8:21: cannot use type C outside a type constraint: interface contains type constraints
./prog.go:11:4: cannot use type C outside a type constraint: interface contains type constraints

not great, but a bit clearer. Closing this for now.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

4 participants