From 3f2b3e5a68d528e532aa49e1982fc25fced1f2b1 Mon Sep 17 00:00:00 2001 From: HarrisL2 Date: Tue, 11 Nov 2025 13:57:34 -0500 Subject: [PATCH] Relax flow typing check on Flexible Types --- .../src/dotty/tools/dotc/core/NullOpsDecorator.scala | 2 +- tests/explicit-nulls/pos/flow-flexible.scala | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/explicit-nulls/pos/flow-flexible.scala diff --git a/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala b/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala index f1ff60e4ea22..572c94070066 100644 --- a/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala +++ b/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala @@ -47,7 +47,7 @@ object NullOpsDecorator: /** Is self (after widening and dealiasing) a type of the form `T | Null`? */ def isNullableUnion(using Context): Boolean = { - val stripped = self.stripNull() + val stripped = self.stripNull(stripFlexibleTypes = false) stripped ne self } end extension diff --git a/tests/explicit-nulls/pos/flow-flexible.scala b/tests/explicit-nulls/pos/flow-flexible.scala new file mode 100644 index 000000000000..ea6d5fef2a95 --- /dev/null +++ b/tests/explicit-nulls/pos/flow-flexible.scala @@ -0,0 +1,9 @@ +// This test is based on sconfig/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfig.scala +// In cases where a nullable variable is assigned a flexible type, we want +// later code to type the variable access as non-nullable +// Added in https://github.com/scala/scala3/pull/24278 + +def main() = + var result: String | Null = null + result = "".trim() + result.trim() \ No newline at end of file