diff options
| author | sriramm-nv <85252063+sriramm-nv@users.noreply.github.com> | 2024-04-05 16:47:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-05 16:47:47 -0700 |
| commit | 1b3887f462d01b83690200b9cbcb0dd902b2c0e9 (patch) | |
| tree | 9b032b6713dd0bd7549635a90ef0280fd691d120 /source/slang/slang-check-stmt.cpp | |
| parent | d61f81374272c2abc34eecab19e916b979b08a55 (diff) | |
Fix __init() functions that returns an existing value (#3866)
Fixes the issue #3671
* The __init constructors are not expected to return a value like other member
functions, but must construct a new value and return the struct type or none.
* This patch enables this behavior in the IR lowering without complaining about
illegal situations where the user returns an invalid type or none at all.
Translate ordinary struct `return ...;` to `this = ...; return this;`
Translate NonCopyableType struct `return ...;` to `return this;`
* This patch also fixes the issue with type checking when __init()
returns a void that mismatches the base type of the struct/ class
Translate ordinary struct `return;` to `return this;`
Translate NonCopyableType struct `return;` to `return;`
* Add end-to-end test and compile only tests to check the above behavior.
Diffstat (limited to 'source/slang/slang-check-stmt.cpp')
| -rw-r--r-- | source/slang/slang-check-stmt.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/source/slang/slang-check-stmt.cpp b/source/slang/slang-check-stmt.cpp index 729b24d35..f7b085579 100644 --- a/source/slang/slang-check-stmt.cpp +++ b/source/slang/slang-check-stmt.cpp @@ -392,7 +392,7 @@ namespace Slang auto function = getParentFunc(); if (!stmt->expression) { - if (function && !function->returnType.equals(m_astBuilder->getVoidType())) + if (function && !function->returnType.equals(m_astBuilder->getVoidType()) && !as<ConstructorDecl>(function)) { getSink()->diagnose(stmt, Diagnostics::returnNeedsExpression); } |
