Type infer issue
See original GitHub issueCompiler version
Tested with 3.0.2
and 3.1.0-RC2
Minimized code
https://github.com/vigoo/scala3-type-infer-bug
Contains a minimal example (the issue originally came up in a parser library under development) and two files from ZIO, Zippable
and Unzippable
as the issue seems to be related to these specific implicits.
Output
[error] 26 | val _ = assertSameType(xy2)
[error] | ^^^
[error] | Found: (Main.xy2 : Example[Int, (AnyVal, Int)])
[error] | Required: Example[T, T]
[error] |
[error] | where: T is a type variable
Expectation
The
val x = pure(1)
val y = pure(2)
val xy1 = x zip y
and
val xy2 = pure(1) zip pure(2)
should both be inferred to the same result, Example[(Int, Int), (Int, Int)]
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
List of all issue types - Infer Static Analyzer
Here is an overview of the issue types currently reported by Infer.
Read more >Argument type infer not work correctly without specify ... - GitHub
A context sensitive function is not fully annotated and so the compiler must use contextual typing to infer something about its type. According ......
Read more >Type inference has usability problems - Austin Z. Henley
People have argued that type inference actually improves readability by removing redundant information from the code that gets in the way.
Read more >Kotlin requires type inference where Java doesn't : KT-5464
I have another issue raised on Spring Framework side due to Kotlin requiring type inference where Java doesn't. Not 100% sure this is...
Read more >Why cannot Typescript infer the type of the function argument ...
But this extra bit of processing after compilation has completed doesn't fix the inference problem. That has already failed, and will only ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In fact, taking a closer look at https://github.com/lampepfl/dotty/issues/13646#issuecomment-933551826, we do have
I
qualifying to be instantiated in the zip example, but it doesn’t get instantiated because of another heuristic: https://github.com/lampepfl/dotty/blob/1ed25ce458d36e773f732267975fbddb0a0be26c/compiler/src/dotty/tools/dotc/typer/Inferencing.scala#L184 which relies on: https://github.com/lampepfl/dotty/blob/1ed25ce458d36e773f732267975fbddb0a0be26c/compiler/src/dotty/tools/dotc/core/Types.scala#L4625-L4630But
I
does have a more precise upper-bound thanAny
in fact, it’s upper-bounded by a type variableA
coming from thepure
method.hasNonWildcardUpperBound
returns false anyway because it relies oncurrentEntry
which only returns the non-variable bounds, if we instead do something like:… then the test case pass. So, probably something worth digging into more.
Could someone suggest a better title for the ticket, to make it easier to find in the future?