diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-check-conversion.cpp | 29 | ||||
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 2 |
2 files changed, 26 insertions, 5 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index c5cf192ee..1c8846e66 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -396,14 +396,35 @@ bool SemanticsVisitor::createInvokeExprForSynthesizedCtor( { StructDecl* structDecl = isDeclRefTypeOf<StructDecl>(toType).getDecl(); - if (!structDecl || !_getSynthesizedConstructor( - structDecl, - ConstructorDecl::ConstructorFlavor::SynthesizedDefault)) + if (!structDecl) return false; HashSet<Type*> isVisit; - bool isCStyle = isCStyleType(toType, isVisit); + bool isCStyle = false; + if (!_getSynthesizedConstructor( + structDecl, + ConstructorDecl::ConstructorFlavor::SynthesizedDefault)) + { + // When a struct has no constructor and it's not a C-style type, the initializer list is + // invalid. + isCStyle = isCStyleType(toType, isVisit); + + // WAR: We currently still has to allow legacy initializer list for array type until we have + // more proper solution for array initialization, so if the right hand side is an array + // type, we will not report error and fall-back to legacy initializer list logic. + bool isArrayType = as<ArrayExpressionType>(toType) != nullptr; + if (!isCStyle && !isArrayType) + { + getSink()->diagnose( + fromInitializerListExpr->loc, + Diagnostics::cannotUseInitializerListForType, + toType); + } + + return false; + } + isCStyle = isCStyleType(toType, isVisit); // TODO: This is just a special case for a backwards-compatibility feature // for HLSL, this flag will imply that the initializer list is synthesized // for a type cast from a literal zero to a 'struct'. In this case, we will fall diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 5ee8ba3ef..34143ad75 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -12412,7 +12412,7 @@ bool SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* struct // any constructors. see: // https://github.com/shader-slang/slang/blob/master/docs/proposals/004-initialization.md#inheritance-initialization if (_hasExplicitConstructor(structDecl, true)) - return false; + return true; // synthesize the signature first. // The constructor's visibility level is the same as the struct itself. |
