From f5304f51a404f9e2c1150f7071ebecc7a8c7f1c2 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Dec 2025 09:08:06 +0530 Subject: [PATCH 1/6] Allow complex float to complex double promotion --- compiler/src/dmd/dcast.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index 8ab49b3c470f..2234fc495a85 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -1604,6 +1604,13 @@ MATCH implicitConvTo(Type from, Type to) if (from.flags & TFlags.complex && !(tob.flags & TFlags.complex)) return MATCH.nomatch; + // Allow complex float to complex double promotion + if ((from.flags & TFlags.complex) && (tob.flags & TFlags.complex)) + { + if (from.size(Loc.initial) <= tob.size(Loc.initial)) + return MATCH.convert; + } + // Disallow implicit conversion of real or imaginary to complex if (from.flags & (TFlags.real_ | TFlags.imaginary) && tob.flags & TFlags.complex) return MATCH.nomatch; From 42fb79716c21507548de2a17fdf769ff87efefcc Mon Sep 17 00:00:00 2001 From: Aryan Dadwal Date: Thu, 25 Dec 2025 09:16:55 +0530 Subject: [PATCH 2/6] Update dcast.d --- compiler/src/dmd/dcast.d | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index 2234fc495a85..4fdfff922310 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -1604,13 +1604,12 @@ MATCH implicitConvTo(Type from, Type to) if (from.flags & TFlags.complex && !(tob.flags & TFlags.complex)) return MATCH.nomatch; - // Allow complex float to complex double promotion + // Allow complex float to complex double promotion if ((from.flags & TFlags.complex) && (tob.flags & TFlags.complex)) { if (from.size(Loc.initial) <= tob.size(Loc.initial)) return MATCH.convert; } - // Disallow implicit conversion of real or imaginary to complex if (from.flags & (TFlags.real_ | TFlags.imaginary) && tob.flags & TFlags.complex) return MATCH.nomatch; From 1555ce32b97e4cb99e5476c6d8c5aed8bf8ca0fb Mon Sep 17 00:00:00 2001 From: Aryan Dadwal Date: Sat, 27 Dec 2025 15:37:18 +0530 Subject: [PATCH 3/6] Create importc_complex_promotion.c --- .../compilable/importc_complex_promotion.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 compiler/test/compilable/importc_complex_promotion.c diff --git a/compiler/test/compilable/importc_complex_promotion.c b/compiler/test/compilable/importc_complex_promotion.c new file mode 100644 index 000000000000..2637eca20710 --- /dev/null +++ b/compiler/test/compilable/importc_complex_promotion.c @@ -0,0 +1,35 @@ +// Ensure complex float can be implicitly promoted to complex double +// Fixes issue #22259 + +#include + +void testComplexPromotion() +{ + // Basic case from issue #22259 + _Complex double x = 1 + 1.0if; + + // Float imaginary with int + _Complex double y = 2 + 3.0if; + + // Two float complex values + _Complex double z = 1.0if + 2.0if; + + // Mixed real and float imaginary + _Complex double w = 5.0 + 1.0if; +} + +void testComplexPreservation() +{ + // These should still work (no change) + _Complex float f1 = 1.0f + 1.0if; + _Complex float f2 = 1.0if + 2.0if; + _Complex double d1 = 1.0 + 2.0i; + _Complex double d2 = 2.0 + 3.0i; +} + +int main() +{ + testComplexPromotion(); + testComplexPreservation(); + return 0; +} From 5f4fde8c70cebd2111275b42c66876372fb9c69e Mon Sep 17 00:00:00 2001 From: Aryan Dadwal Date: Sat, 27 Dec 2025 15:42:59 +0530 Subject: [PATCH 4/6] Update importc_complex_promotion.c --- compiler/test/compilable/importc_complex_promotion.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/compiler/test/compilable/importc_complex_promotion.c b/compiler/test/compilable/importc_complex_promotion.c index 2637eca20710..94cfe2eeea19 100644 --- a/compiler/test/compilable/importc_complex_promotion.c +++ b/compiler/test/compilable/importc_complex_promotion.c @@ -1,23 +1,17 @@ // Ensure complex float can be implicitly promoted to complex double // Fixes issue #22259 - #include - void testComplexPromotion() { // Basic case from issue #22259 _Complex double x = 1 + 1.0if; - // Float imaginary with int _Complex double y = 2 + 3.0if; - // Two float complex values _Complex double z = 1.0if + 2.0if; - // Mixed real and float imaginary _Complex double w = 5.0 + 1.0if; } - void testComplexPreservation() { // These should still work (no change) @@ -26,7 +20,6 @@ void testComplexPreservation() _Complex double d1 = 1.0 + 2.0i; _Complex double d2 = 2.0 + 3.0i; } - int main() { testComplexPromotion(); From 223d1331a5f07d87544d38c02c171db74405e0bf Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 27 Dec 2025 16:12:34 +0530 Subject: [PATCH 5/6] Fix #22259: Change <= to < for correct complex type promotion logic --- compiler/src/dmd/dcast.d | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/src/dmd/dcast.d b/compiler/src/dmd/dcast.d index 4fdfff922310..55aa781f758a 100644 --- a/compiler/src/dmd/dcast.d +++ b/compiler/src/dmd/dcast.d @@ -1603,13 +1603,6 @@ MATCH implicitConvTo(Type from, Type to) // Disallow implicit conversion from complex to non-complex if (from.flags & TFlags.complex && !(tob.flags & TFlags.complex)) return MATCH.nomatch; - - // Allow complex float to complex double promotion - if ((from.flags & TFlags.complex) && (tob.flags & TFlags.complex)) - { - if (from.size(Loc.initial) <= tob.size(Loc.initial)) - return MATCH.convert; - } // Disallow implicit conversion of real or imaginary to complex if (from.flags & (TFlags.real_ | TFlags.imaginary) && tob.flags & TFlags.complex) return MATCH.nomatch; @@ -1617,6 +1610,12 @@ MATCH implicitConvTo(Type from, Type to) // Disallow implicit conversion to-from real and imaginary if ((from.flags & (TFlags.real_ | TFlags.imaginary)) != (tob.flags & (TFlags.real_ | TFlags.imaginary))) return MATCH.nomatch; + // Allow complex float to complex double promotion + if ((from.flags & TFlags.complex) && (tob.flags & TFlags.complex)) + { + if (from.size(Loc.initial) < tob.size(Loc.initial)) + return MATCH.convert; + } } return MATCH.convert; From 37f039e94976cbbf27d65e9e326d43a4be629047 Mon Sep 17 00:00:00 2001 From: Aryan Dadwal Date: Sat, 27 Dec 2025 16:23:20 +0530 Subject: [PATCH 6/6] Update importc_complex_promotion.c --- .../test/compilable/importc_complex_promotion.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/test/compilable/importc_complex_promotion.c b/compiler/test/compilable/importc_complex_promotion.c index 94cfe2eeea19..3271aa23a519 100644 --- a/compiler/test/compilable/importc_complex_promotion.c +++ b/compiler/test/compilable/importc_complex_promotion.c @@ -1,17 +1,13 @@ // Ensure complex float can be implicitly promoted to complex double // Fixes issue #22259 #include + void testComplexPromotion() { - // Basic case from issue #22259 - _Complex double x = 1 + 1.0if; - // Float imaginary with int - _Complex double y = 2 + 3.0if; - // Two float complex values - _Complex double z = 1.0if + 2.0if; - // Mixed real and float imaginary - _Complex double w = 5.0 + 1.0if; + _Complex float yf = 1.0if; + _Complex double x = yf; // promotion: _Complex float -> _Complex double } + void testComplexPreservation() { // These should still work (no change) @@ -20,6 +16,7 @@ void testComplexPreservation() _Complex double d1 = 1.0 + 2.0i; _Complex double d2 = 2.0 + 3.0i; } + int main() { testComplexPromotion();