Issue #26: Detect empty array constructors, require at least on operand.

This commit is contained in:
John Kessenich 2015-07-21 14:35:39 -06:00
Родитель 222457054e
Коммит efb8461722
3 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -100,3 +100,5 @@ void foo3()
resize2.length(); resize2.length();
resize2[5] = 4.0; // ERROR resize2[5] = 4.0; // ERROR
} }
int[] i = int[](); // ERROR, need constructor arguments

Просмотреть файл

@ -22,7 +22,9 @@ ERROR: 0:79: '' : array size required
ERROR: 0:84: 'return' : type does not match, or is not convertible to, the function's return type ERROR: 0:84: 'return' : type does not match, or is not convertible to, the function's return type
ERROR: 0:93: 'length' : array must be declared with a size before using this method ERROR: 0:93: 'length' : array must be declared with a size before using this method
ERROR: 0:101: '[' : array index out of range '5' ERROR: 0:101: '[' : array index out of range '5'
ERROR: 23 compilation errors. No code generated. ERROR: 0:104: 'constructor' : array constructor must have at least one argument
ERROR: 0:104: '=' : cannot convert from 'const float' to 'global implicitly-sized array of int'
ERROR: 25 compilation errors. No code generated.
Shader version: 130 Shader version: 130
@ -264,6 +266,7 @@ ERROR: node is still EOpNull!
0:? 'guns' (global implicitly-sized array of 3-component vector of float) 0:? 'guns' (global implicitly-sized array of 3-component vector of float)
0:? 'f' (global float) 0:? 'f' (global float)
0:? 'gUnusedUnsized' (global implicitly-sized array of float) 0:? 'gUnusedUnsized' (global implicitly-sized array of float)
0:? 'i' (global implicitly-sized array of int)
Linked fragment stage: Linked fragment stage:
@ -508,4 +511,5 @@ ERROR: node is still EOpNull!
0:? 'guns' (global 8-element array of 3-component vector of float) 0:? 'guns' (global 8-element array of 3-component vector of float)
0:? 'f' (global float) 0:? 'f' (global float)
0:? 'gUnusedUnsized' (global 1-element array of float) 0:? 'gUnusedUnsized' (global 1-element array of float)
0:? 'i' (global 1-element array of int)

Просмотреть файл

@ -1973,6 +1973,10 @@ bool TParseContext::constructorError(TSourceLoc loc, TIntermNode* node, TFunctio
type.getQualifier().storage = EvqConst; type.getQualifier().storage = EvqConst;
if (type.isArray()) { if (type.isArray()) {
if (function.getParamCount() == 0) {
error(loc, "array constructor must have at least one argument", "constructor", "");
return true;
}
if (type.isImplicitlySizedArray()) { if (type.isImplicitlySizedArray()) {
// auto adapt the constructor type to the number of arguments // auto adapt the constructor type to the number of arguments
type.changeArraySize(function.getParamCount()); type.changeArraySize(function.getParamCount());
@ -1992,7 +1996,7 @@ bool TParseContext::constructorError(TSourceLoc loc, TIntermNode* node, TFunctio
// "If a matrix argument is given to a matrix constructor, // "If a matrix argument is given to a matrix constructor,
// it is a compile-time error to have any other arguments." // it is a compile-time error to have any other arguments."
if (function.getParamCount() > 1) if (function.getParamCount() != 1)
error(loc, "matrix constructed from matrix can only have one argument", "constructor", ""); error(loc, "matrix constructed from matrix can only have one argument", "constructor", "");
return false; return false;
} }