diff options
| author | Yong He <yonghe@outlook.com> | 2025-07-22 08:47:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 15:47:50 +0000 |
| commit | 52a45890b5ab71d7dbfdd01955afce129728d67e (patch) | |
| tree | 141491e9c36cfa6a1a890765682d69ac4bfd2270 /tests | |
| parent | 0d26dbaad90f5eac604e148971d14e552bf9d5b8 (diff) | |
Fix crash when private ctor is used for coercion. (#7858)
* Fix crash when private ctor is used for coercion.
* Fix tests.
* Fix.
* Fix test error.
Diffstat (limited to 'tests')
5 files changed, 69 insertions, 6 deletions
diff --git a/tests/autodiff/diff-assoctype-generic-interface.slang b/tests/autodiff/diff-assoctype-generic-interface.slang index 79e0eff08..6640e1d94 100644 --- a/tests/autodiff/diff-assoctype-generic-interface.slang +++ b/tests/autodiff/diff-assoctype-generic-interface.slang @@ -15,6 +15,7 @@ struct GetterImpl : IGetter { float[8] data; + [Differentiable] __init(float[8] data) { this.data = data; } diff --git a/tests/diagnostics/private-visibility.slang b/tests/diagnostics/private-visibility.slang index 7c0bad970..b7cb628f4 100644 --- a/tests/diagnostics/private-visibility.slang +++ b/tests/diagnostics/private-visibility.slang @@ -24,21 +24,20 @@ struct MyType get { return member; } set { member = newValue; } } - // CHECK:{{.*}}(28): error 30601: + // CHECK:{{.*}}([[# @LINE+1]]): error 30601: public void publicMethod() {} // ERROR. } void test() { - // CHECK:{{.*}}(34): error 30600: - MyType t; // ERROR. + MyType t; // should leave uninitialized. // CHECK-NOT:{{.*}}error t.func1(); // OK. - // CHECK:{{.*}}(38): error 30600: + // CHECK:{{.*}}([[# @LINE+1]]): error 30600: t.func(); // ERROR. - // CHECK:{{.*}}(40): error 30600: + // CHECK:{{.*}}([[# @LINE+1]]): error 30600: t[0] = 1; // ERROR. - // CHECK:{{.*}}(43): error 30600: + // CHECK:{{.*}}([[# @LINE+1]]): error 30600: t.member = 2; } diff --git a/tests/language-server/private-ctor-call/bsdfs.slang b/tests/language-server/private-ctor-call/bsdfs.slang new file mode 100644 index 000000000..ff50ab352 --- /dev/null +++ b/tests/language-server/private-ctor-call/bsdfs.slang @@ -0,0 +1,28 @@ +module bsdfs; +__include lambert_diffuse_btdf; + +public struct BSDFContext +{ + float iorI; ///< IOR from incidence medium + float iorT; ///< IOR trom transmission medium + bool inited; ///< Flag to indicate if the struct was initialized + + __init(float iorI_, float iorT_) + { + iorI = iorI_; + iorT = iorT_; + inited = true; + } + + __init() + { + iorI = 1.f; + iorT = 1.f; + inited = false; + } +} + +public interface IBSDF +{ + public float3 eval(const float3 wi, const float3 wo, BSDFContext bc); +} diff --git a/tests/language-server/private-ctor-call/lambert_diffuse_btdf.slang b/tests/language-server/private-ctor-call/lambert_diffuse_btdf.slang new file mode 100644 index 000000000..82f766da4 --- /dev/null +++ b/tests/language-server/private-ctor-call/lambert_diffuse_btdf.slang @@ -0,0 +1,22 @@ +implementing bsdfs; +public struct LambertDiffuseBTDF : IBSDF, IDifferentiable +{ + float3 albedo = {}; ///< Diffuse albedo. +#if 0 + public __init(float3 albedo_) +#else + __init(float3 albedo_) +#endif + { + this.albedo = albedo_; + } + + [Differentiable] + public float3 eval(const float3 wi, const float3 wo, BSDFContext bc) + { + if (min(wi.z, -wo.z) < 1e-6f) + return float3(0.f); + + return (1.0 / 3.1415) * albedo * -wo.z; + } +} diff --git a/tests/language-server/private-ctor-call/test-main.slang b/tests/language-server/private-ctor-call/test-main.slang new file mode 100644 index 000000000..2074c3b8d --- /dev/null +++ b/tests/language-server/private-ctor-call/test-main.slang @@ -0,0 +1,13 @@ +//TEST:LANG_SERVER(filecheck=CHECK): + +module "test-main"; + +import bsdfs; + +LambertDiffuseBTDF createTranslucent(float3 color, float3 normal) +{ +//HOVER:10,21 + return LambertDiffuseBTDF( color ); +} + +//CHECK: LambertDiffuseBTDF.init |
