Skip to content

cmd/compile: odd type error reported on the wrong line #49441

Closed
@aarzilli

Description

@aarzilli

This code:

package main

type pointerToT[T any, PT pointerToT[T, PT]] interface{
	*T
}

func F[T any, PT pointerToT[T, PT]](n, nn PT) {
}

compiles just fine, however adding a new function definition, calling F:

package main

type pointerToT[T any, PT pointerToT[T, PT]] interface{
	*T
}

func F[T any, PT pointerToT[T, PT]](n, nn PT) {
}

func WrapF[A any, PA pointerToT[A, PA]](n, nn PA) {
	F(n, nn)
}

Causes the error: ./buggy.go:7:15: PT does not match *T on the line declaring F. It's weird that declaring a function would cause a different function to no longer typecheck correctly, I think this error was meant to be reported on the call to F.
It's also unclear what the problem is, shouldn't the type inference work correctly? Manually instantiating F as F[A, PA](n, nn) makes the error go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.genericsIssue is related to generics

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions