Skip to content

Commit 02b84cf

Browse files
committed
Fix oslc assertion on type constructor for unknown struct (#988)
The assertion was not needed, errors issue before this code is reached.
1 parent 7f750c9 commit 02b84cf

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ TESTSUITE ( aastep allowconnect-err and-or-not-synonyms arithmetic
301301
oslc-err-outputparamvararray oslc-err-paramdefault
302302
oslc-err-struct-array-init oslc-err-struct-ctr
303303
oslc-err-struct-dup oslc-err-struct-print
304+
oslc-err-unknown-ctr
304305
oslc-warn-commainit
305306
oslc-variadic-macro
306307
oslc-version

src/liboslcomp/typecheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,12 @@ OSLCompilerImpl::code_from_type (TypeSpec type) const
22722272
out = 's';
22732273
else if (elem == TypeDesc::NONE)
22742274
out = 'x';
2275-
else
2276-
ASSERT (0);
2275+
else {
2276+
out = 'x';
2277+
// This only happens in error circumstances. Seems safe to
2278+
// return the code for 'void' and hope everything sorts itself
2279+
// out with the downstream errors.
2280+
}
22772281
}
22782282

22792283
if (type.is_array()) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test.osl:4: error: Unknown struct name: mat2
2+
test.osl:6: error: function 'mat2' was not declared in this scope
3+
test.osl:6: error: No matching function call to 'mat2 (float, float, float, float)'
4+
FAILED test.osl
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
3+
# command = oslc("test.osl")
4+
# don't even need that -- it's automatic
5+
failureok = 1 # this test is expected to have oslc errors
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// No mat2 is known. This used to hit an assertion.
2+
// Correct behavior is understandable error message(s).
3+
4+
mat2 rotmat(float a)
5+
{
6+
return mat2(cos(a),sin(a),-sin(a),cos(a));
7+
}
8+
9+
shader test ()
10+
{
11+
printf ("Did not crash\n");
12+
}

0 commit comments

Comments
 (0)