https://github.com/shader-slang/slang
Revision 93a444fe1b5f1e3c6da67db4d948df53a0bdb3f6 authored by Tim Foley on 07 November 2017, 17:38:32 UTC, committed by Tim Foley on 07 November 2017, 18:44:07 UTC
Subscript declarations can have nested "accessor" declarations for the get/set behavior:

```
__subscript(int index) -> float
{
    get { ... }
    set { ... }
}
```

The AST type checks an expression like `a[i]` into a call to an appropriate `__subscript` declaration, and reads the return type off of that, but doesn't drill down to the individual getters/setters.

During IR code generation, we need to resolve a call to the subscript operation down to the actual getter or setter, since those are what will have the executable code (or be intrinsics). If we have a non-intrinsic accessor, then we end up asking for its "return type" and get NULL, which crashes the compiler.

The fix in this case is to add a bit more semantic checking for accessors, mostly just so that we can have them copy the return type from their parent declaration. While we are at it, this change goes ahead and has an accessor validate that the parent declaration is one that should be allowed, and emit a diagnostic if it is nested in an improper place.
1 parent 9640df0
History
Tip revision: 93a444fe1b5f1e3c6da67db4d948df53a0bdb3f6 authored by Tim Foley on 07 November 2017, 17:38:32 UTC
Attach correct types to subscript accessors
Tip revision: 93a444f
File Mode Size
build
docs
examples
external
source
tests
tools
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 398 bytes
.gitmodules -rw-r--r-- 107 bytes
.travis.yml -rw-r--r-- 1.6 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
Makefile -rw-r--r-- 6.3 KB
README.md -rw-r--r-- 6.2 KB
appveyor.yml -rw-r--r-- 3.5 KB
slang.h -rw-r--r-- 35.4 KB
slang.sln -rw-r--r-- 9.1 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top