diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-12 07:57:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-12 07:57:42 -0700 |
| commit | 4ae6e9d8b7790d827ca9edd729ad94f38a0c73de (patch) | |
| tree | 1aad23cae09dacf9d3377d040cbc9ac84b48675e /source/slang/slang-check-decl.cpp | |
| parent | 7dad68f869502e5c0ab32c12cbf8db866e020713 (diff) | |
Diagnose on use of struct inheritance. (#7419)
* Diagnose on use of struct inheritance.
* fix test.
* Fix tests.
* fix.
---------
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 2865188b4..ddc4ec4d5 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -7811,7 +7811,7 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl) { getSink()->diagnose( inheritanceDecl, - Diagnostics::baseOfStructMustBeStructOrInterface, + Diagnostics::baseOfStructMustBeInterface, decl, baseType); continue; @@ -7823,6 +7823,26 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl) } else if (auto baseStructDeclRef = baseDeclRef.as<StructDecl>()) { + if (!isFromCoreModule(decl)) + { + // In Slang 2026, we no longer allow structs to inherit from other structs. + if (isSlang2026OrLater(this)) + { + getSink()->diagnose( + inheritanceDecl, + Diagnostics::baseOfStructMustBeInterface, + decl, + baseType); + } + else + { + // For legacy langauge versions, we still allow struct inheritance to avoid + // breaking existing code, but we will emit a warning to inform the user + // that this feature is unstable and may be removed in the future. + getSink()->diagnose(inheritanceDecl, Diagnostics::inheritanceUnstable); + } + } + // To simplify the task of reading and maintaining code, // we require that when a `struct` inherits from another // `struct`, the base `struct` is the first item in @@ -7845,7 +7865,7 @@ void SemanticsDeclBasesVisitor::visitStructDecl(StructDecl* decl) { getSink()->diagnose( inheritanceDecl, - Diagnostics::baseOfStructMustBeStructOrInterface, + Diagnostics::baseOfStructMustBeInterface, decl, baseType); continue; |
