<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/diagnostics/generic-constraint-forward-reference.slang.expected, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2025-07-08T23:15:51+00:00</updated>
<entry>
<title>Add error for forward references in generic constraints (#7615)</title>
<updated>2025-07-08T23:15:51+00:00</updated>
<author>
<name>sricker-nvidia</name>
<email>115114531+sricker-nvidia@users.noreply.github.com</email>
</author>
<published>2025-07-08T23:15:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=2c4bfce49d9af2414f6a3f70f7221d6890a017e7'/>
<id>urn:sha1:2c4bfce49d9af2414f6a3f70f7221d6890a017e7</id>
<content type='text'>
* Add error for forward references in generic constraints

Change addresses issue #6545.

The slang compiler's type checker is unable to support cases where
a generic type parameter is referenced as a constraint before it is
declared. For example code like:

````
interface IFoo&lt;T : IFloat&gt;
{
}

void bar&lt;Foo : IFoo&lt;T&gt;, T : IFloat&gt;()
{
}
````

Is not supported, but will currently report a generic error like,

"(0): error 99999: Slang compilation aborted due to an exception
of class Slang::InternalError: unexpected: generic type constraint
during lowering"

This change adds a new check for this kind of code and reports an
error like,

"error 30117: generic constraint for parameter 'Foo' references type
parameter 'T' before it is declared"

when detected. Basic testing of this error is also added in a new
diagnostic test.

* Add error for forward refs in generic constiants update 1

* Add error for forward refs in generic constraints update 2

Revised algo in checkForwardReferencesInGenericConstraint to run
in O(n) instead of the previous O(n^2) using HashSets.

* Add error for forward refs in generic constraints update 3

-Update logic adding referenced decl's in collectReferencedDecls.
-Simplified error string logic.

* Add error for forward refs in generic constraints update 4

-Declare collectReferencedDecls in slang-check.h such that it can
 be used as a general utility function.

* format code

---------

Co-authored-by: slangbot &lt;186143334+slangbot@users.noreply.github.com&gt;</content>
</entry>
</feed>
