Skip to content

Capture checking type mismatch between types that are reported to be the same #23027

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
05st opened this issue Apr 22, 2025 · 0 comments
Open
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@05st
Copy link

05st commented Apr 22, 2025

Compiler version

3.7.0-RC1

Minimized code

import language.experimental.captureChecking

trait Test {
    def foo(x: Test): Test =
        Test.bar
        ???
}

object Test {
    val _bar: Any => Any = identity
    def bar[T] = _bar.asInstanceOf[T => T]
}

If we change this line it compiles fine:

    def bar[T] = _bar.asInstanceOf//[T => T]

It also compiles fine if we disable capture checking (i.e. remove the captureChecking import).

Minimized from Future

Output

[error] -- [E007] Type Mismatch Error
[error] 11 |    def bar[T] = _bar.asInstanceOf[T => T]
[error]    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |             Found:    T => T
[error]    |             Required: T => T
[error]    |
[error]    |             Note that the expected type T => T
[error]    |             is the previously inferred result type of method bar
[error]    |             which is also the type seen in separately compiled sources.
[error]    |             The new inferred type T => T
[error]    |             must conform to this type.

Expectation

The type mismatch seems to be caused by some hidden difference in the types which is not being reported in the error. The error message should show this difference.

@05st 05st added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 22, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

1 participant