Skip to content

Internal compiler error when passing associated type value to unconstrained generic #9934

@jvepsalainen-nv

Description

@jvepsalainen-nv

Issue Description

Passing the return value of an interface method (whose return type is an associated type) to an unconstrained generic function causes an internal compiler error instead of producing a diagnostic.

Reproducer Code

#lang slang 2025

interface ITransform
{
    associatedtype Output;
    Output transform(float x);
}

struct FloatTransform : ITransform
{
    typealias Output = float;
    float transform(float x) { return x * 2; }
}

struct IntTransform : ITransform
{
    typealias Output = int;
    int transform(float x) { return int(x); }
}

T process<T>(T val) { return val; }

ITransform factory(uint id)
{
    if (id == 0) return FloatTransform();
    return IntTransform();
}

RWStructuredBuffer<float> outputBuffer;

[numthreads(1, 1, 1)]
void computeMain(uint3 tid : SV_DispatchThreadID)
{
    ITransform obj = factory(tid.x);
    var result = obj.transform(1.0);
    let processed = process(result);
    outputBuffer[0] = 0;
}

Command:

slangc -target spirv-asm -o /dev/null test.slang

Expected Behavior

The compiler should reject the program with error 33180 ("specializing ... with an existential type is not allowed"), since the type of result depends on the associated type of an existential and cannot be statically resolved.

Note: the constrained generic variant (process<T : ITransform>(T obj, ...) called with an existential) correctly produces error 33180.

Actual Behavior

(0): error 99999: Slang compilation aborted due to an exception of N5Slang13InternalErrorE:
unexpected: Unexpected operand type for type-flow specialization of Call inst

Environment

  • Slang Version: eaa54ed (master)
  • OS: macOS
  • Target: All targets (spirv, hlsl, etc.)

Metadata

Metadata

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions