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/language-server | |
| 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/language-server')
3 files changed, 63 insertions, 0 deletions
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 |
