<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/diagnostics/call-instance-from-static.slang, 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>2020-04-21T22:41:52+00:00</updated>
<entry>
<title>Diagnose attempts to call instance methods from static methods (#1330)</title>
<updated>2020-04-21T22:41:52+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2020-04-21T22:41:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=58904b58bcc5436950dcae6680c9214e6361be92'/>
<id>urn:sha1:58904b58bcc5436950dcae6680c9214e6361be92</id>
<content type='text'>
Currently we fail to diagnose code that calls an instance method from a static method using implicit `this`, and instead crash during lowering of the AST to the IR.

This change introduces a bit more detail to the "this parameter mode" that is computed during lookup, so that it differentiates three cases. The existing two cases of a mutable `this` and immutable `this` remain, but we add a third case where the "this parameter mode" only allows for a reference to the `This` type.

When turning lookup "breadcrumb" information into actual expressions, we respect this setting to construct either a `This` or `this` expression.

In order to actually diagnose the incorrect reference, I had to add code around an existing `TODO` comment that noted how we should diagnose attempts to refer to instance members through a type. Enabling that diagnostic revealed a missing case needed by generics (including those in the stdlib) - a type-constraint member is always referenced statically.

Putting the diagnostic for a static reference to a non-static member in its new bottleneck location meant that some code higher up the call static that handles explicit static member references had to be tweaked to not produce double error messages.

This change includes a new diagnostic test to show that we now give an error message on code that makes this mistake, instead of crashing.</content>
</entry>
</feed>
