Skip to content

Generic struct specialization rejects valid associated-type equality constraint #12822

Description

@tangent-vector

Summary

Specializing a generic struct can reject a valid equality constraint on an associated type, even
when the concrete conformance supplies exactly the required associated type.

This reproducer uses only user-space interfaces and types. It has no dependency on autodiff,
numeric interfaces, or builtin core-module conformances.

Reproducer

interface IHasElement
{
    associatedtype Element;
}

struct ConcreteElement {}

struct Container : IHasElement
{
    typealias Element = ConcreteElement;
}

struct RequiresConcreteElement<T : IHasElement>
    where T.Element == ConcreteElement
{}

RequiresConcreteElement<Container> value;

Compile with:

slangc repro.slang -target none

Expected behavior

The source compiles. Container conforms to IHasElement, and its witness explicitly defines
Container.Element as ConcreteElement, so the specialization satisfies
T.Element == ConcreteElement.

Actual behavior

error[E38029]: type argument doesn't conform to interface
  --> repro.slang:17:1
   |
17 | RequiresConcreteElement<Container> value;
   | ^^^^^^^^^^^^^^^^^^^^^^^ type argument 'Container.Element' does not conform to the required interface 'ConcreteElement'
---'

The diagnostic also describes one endpoint of a type equality as an interface, which obscures the
underlying failed equality check.

Scope and controls

  • The failure does not depend on T.Element == T: an unrelated user-defined ConcreteElement on
    the right-hand side fails as shown above.
  • Reversing the equality to ConcreteElement == T.Element does not change the result.
  • Adding a second generic parameter U and writing where T.Element == U also fails when
    specializing with the matching concrete types.
  • The equivalent constraint on a generic function successfully specializes for the same user
    types. The failing path therefore appears specific to validation or specialization of a generic
    type.

This appears related to #6714. That issue's nested generic-type reproducer was reported as no longer
reproducing at 996ebcbdc, but its original shape also produces E38029 with the compiler version
below. The smaller reproducer here shows that neither nesting nor array associated types are
required, so this may be a regression or a remaining generic-type specialization path not covered
by the earlier fix.

Version tested

2026.14.1-80-gd4c72aab0

Metadata

Metadata

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions