Skip to content

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Sep 16, 2025

Based on #23911

Fixes #23908

Could fix #23933, #23935, #23936, and #23937 (I tested locally)?

DO NOT MERGE: the explicit nulls tests are currently broken

cc @olhotak @HarrisL2

@noti0na1 noti0na1 requested review from Copilot and olhotak September 16, 2025 20:58
Copilot

This comment was marked as outdated.

@noti0na1 noti0na1 self-assigned this Sep 16, 2025
@noti0na1 noti0na1 marked this pull request as ready for review September 16, 2025 23:56
Copy link
Contributor

@olhotak olhotak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

Comment on lines +206 to +212
case FlexibleType(_, parent2a) if ctx.flexibleTypes =>
FlexibleType(derivedRefinedType(tp, parent2a, refinedInfo2))
case OrNull(parent2a) =>
OrNull(derivedRefinedType(tp, parent2a, refinedInfo2))
case _ =>
derivedRefinedType(tp, parent2, refinedInfo2)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer this approach? @olhotak

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try it.

I'm a bit nervous about flexifying the parent type and then undoing that (what if it was previously flexified already?), but we can try it.

A simpler approach would be to always flexify the refined type at the top level but then to not flexify the parent type. That may unnecessarily flexify a refined type in cases when the parent is one of the types that we don't flexify (such as a primitive type), but it seems unlikely that people would want to refine such types.

I think it doesn't make sense to flexify the parent type because it doesn't make sense to refine null. You wouldn't say (Foo|null) { def bar(): Int }. Instead, you could say (Foo { def bar(): Int }) | Null.

@noti0na1
Copy link
Member Author

I have run the compilation tests locally. The tests below fail because of the current awkward stage of stdlib.

tests/explicit-nulls/pos/flow-predef-eq.scala
tests/explicit-nulls/pos/eq-ne.scala
tests/explicit-nulls/warn/expose-flexible-types.scala

@WojciechMazur
Copy link
Contributor

It seems to be fixing 13 projects in the OpenCB, however some of reported projects are now failing with different errors requring wrong number of arguments - I have not seen errors like that before.
All of the following projects were previously affected by FlexibleTypes match errors, there might be more but I have not yet manged to analyze their results.

Error:  166 |          check(genTuple(Gen.int, Gen.int.filter(_ != 0))) { (num, div) =>
Error:      |                                                             ^
Error:      |                               Wrong number of parameters, expected: 1
Error:  167 |            val eff = zArrow(num).provide(ZLayer.succeed(div))
Error:  168 |            assertZIO(eff)(equalTo(num / div))
Error:      |
Error:  -- [E086] Syntax Error: /build/repo/ordset/src/ordset/util/ShowUtil.scala:62:67 
Error:  62 |        val indentedLines = lines.zipWithIndex.map { (line, index) => 
Error:     |                                                     ^
Error:     |                                 Wrong number of parameters, expected: 1
Error:  63 |          if (index == 0) line else fieldIndent + line
Error:     |
Error:     | longer explanation available when compiling with `-explain`
Error:  -- [E046] Cyclic Error: /build/repo/facsimile-util/src/test/scala/org/facsim/util/test/MemoizeTest.scala:224:17 
Error:  224 |          forAll { (il: List[Int]) =>
Error:      |                 ^
Error:      |                 Cyclic reference involving trait BitSet
Error:      |
Error:      |                  Run with -explain-cyclic for more details.
Error:      |
Error:  -- [E007] Type Mismatch Error: /build/repo/univeq/shared/src/main/scala-3/japgolly/univeq/internal/Derivation.scala:78:61 
Error:  78 |                log("  - Checking: " + Type.show(using fUnit.asType))
Error:     |                                                       ^^^^^^^^^^^^
Error:     |               Found:    (scala.quoted.Type[? <: AnyKind])?
Error:     |               Required: scala.quoted.Type[T]
Error:     |
Error:     |               where:    T is a type variable with constraint <: AnyKind
Error:     |
Error:     | longer explanation available when compiling with `-explain`

@olhotak
Copy link
Contributor

olhotak commented Sep 17, 2025

I would guess that the errors about wrong number of arguments are due to some failure of auto-tupling probably getting confused by flexible types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-Yexplicit-nulls breaks enums Crash with FlexibleTypes when nullifying classes with Higher-kinded Type Parameters
4 participants