Skip to content

cmd/compile: improve error message for invalid use of interface with type constraints #50837

Closed

Description

@virtuald

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

Activity

  1. changed the title [-]compiler?: Improve interface with type constraint compilation error[/-] [+]cmd/compile: improve error message for invalid use of interface with type constraints[/+] on Jan 26, 2022
  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jan 26, 2022
  3. added this to the Go1.19 milestone on Jan 26, 2022
  4. ianlancetaylor commented on Jan 26, 2022

    @ianlancetaylor
    Contributor
  5. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jan 27, 2022
  6. griesemer commented on Jan 27, 2022

    @griesemer
    Contributor

    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.

  7. self-assigned this
    on Jan 27, 2022
  8. griesemer commented on Jun 23, 2022

    @griesemer
    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.

  9. locked and limited conversation to collaborators on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions