Skip to content

Disallow polymorphic function types over impure function types#26084

Merged
bracevac merged 3 commits into
scala:mainfrom
dotty-staging:fix-26035
May 28, 2026
Merged

Disallow polymorphic function types over impure function types#26084
bracevac merged 3 commits into
scala:mainfrom
dotty-staging:fix-26035

Conversation

@odersky
Copy link
Copy Markdown
Contributor

@odersky odersky commented May 18, 2026

Disallowed and rejected with an implementation restriction error:

[A] => B => C

OK:

[A] => B -> C

Also OK (and equivalent to last one):

[A] -> B -> C

This is necessary since our current polymorphic function encoding requires that the type that's quantified over is a pure function type. We should fix that but until that's done we need to enforce the restriction.

Fixes #26035

@odersky odersky requested a review from a team as a code owner May 18, 2026 14:30
@odersky odersky requested a review from bracevac May 18, 2026 14:31
@odersky
Copy link
Copy Markdown
Contributor Author

odersky commented May 18, 2026

@bracevac There are some scaladoc tests failing, which probably means scaladoc pages are now wrong as well. Can you take a look?

Comment thread tests/pos-custom-args/captures/i24309-region.scala
Comment thread compiler/src/dotty/tools/dotc/parsing/Parsers.scala Outdated
Comment thread tests/neg-custom-args/captures/i26035.scala
@bracevac
Copy link
Copy Markdown
Contributor

@bracevac There are some scaladoc tests failing, which probably means scaladoc pages are now wrong as well. Can you take a look?

It's because the rendering test captureCheckingSignatures.scala tests some lambdas that are now illegal. These just need to be commented out:

Error:  -- Error: /home/runner/work/scala3/scala3/scaladoc-testcases/src/tests/captureCheckingSignatures.scala:82:22 
Error:  82 |  val polyPureV2: [A] => Int => A ->{a,b,c} Int //expected: val polyPureV2: [A] => Int => A ->{a, b, c} Int
Error:     |                      ^
Error:     |Implementation restriction: polymorphic function types cannot wrap impure function types if capture checking is enabled
Error:  -- Error: /home/runner/work/scala3/scala3/scaladoc-testcases/src/tests/captureCheckingSignatures.scala:83:23 
Error:  83 |  val polyImpureV: [A] -> A => Int //expected: val polyImpureV: [A] => A => Int
Error:     |                       ^
Error:     |Implementation restriction: polymorphic function types cannot wrap impure function types if capture checking is enabled
Error:  -- Error: /home/runner/work/scala3/scala3/scaladoc-testcases/src/tests/captureCheckingSignatures.scala:84:24 
Error:  84 |  val polyImpureV2: [A] -> A => Int //expected: val polyImpureV2: [A] => A => Int
Error:     |                        ^
Error:     |Implementation restriction: polymorphic function types cannot wrap impure function types if capture checking is enabled

@bracevac bracevac assigned odersky and unassigned bracevac May 19, 2026
@odersky
Copy link
Copy Markdown
Contributor Author

odersky commented May 19, 2026

@bracevac Good suggestions. Can you take the PR over?

@bracevac bracevac assigned bracevac and unassigned odersky May 19, 2026
odersky added 2 commits May 27, 2026 14:28
Disallowed:

    [A] => B => C

OK:

    [A] => B -> C

Also OK (and equivalent to last one):

    [A] -> B -> C
@bracevac bracevac requested review from bracevac and noti0na1 May 27, 2026 22:38
@bracevac bracevac merged commit fbc982c into scala:main May 28, 2026
49 of 50 checks passed
@bracevac bracevac deleted the fix-26035 branch May 28, 2026 05:13
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.

Capture leak by using Polymorphic Function Types

3 participants