File tree 3 files changed +44
-2
lines changed
compiler/src/dotty/tools/dotc
3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -4895,9 +4895,12 @@ object Types {
4895
4895
/** For uninstantiated type variables: Is the lower bound different from Nothing? */
4896
4896
def hasLowerBound (using Context ): Boolean = ! currentEntry.loBound.isExactlyNothing
4897
4897
4898
- /** For uninstantiated type variables: Is the upper bound different from Any? */
4898
+ /** For uninstantiated type variables: Is the upper bound different from Any or any type constructor ? */
4899
4899
def hasUpperBound (using Context ): Boolean = ! currentEntry.hiBound.finalResultType.isExactlyAny
4900
4900
4901
+ /** For uninstantiated type variables: Is the upper bound different from Any? */
4902
+ def hasUpperBoundSimpleKind (using Context ): Boolean = ! currentEntry.hiBound.isExactlyAny
4903
+
4901
4904
/** Unwrap to instance (if instantiated) or origin (if not), until result
4902
4905
* is no longer a TypeVar
4903
4906
*/
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ object Inferencing {
182
182
if minimizeSelected then
183
183
if direction <= 0 && tvar.hasLowerBound then
184
184
instantiate(tvar, fromBelow = true )
185
- else if direction >= 0 && tvar.hasUpperBound then
185
+ else if direction >= 0 && tvar.hasUpperBoundSimpleKind then
186
186
instantiate(tvar, fromBelow = false )
187
187
// else hold off instantiating unbounded unconstrained variable
188
188
else if direction != 0 then
Original file line number Diff line number Diff line change
1
+ import scala .language .implicitConversions
2
+
3
+ // We do have 2 `contramap` functions, one provided via `LoggerSyntax` other via `Contravariant.Ops`
4
+ // `ContravariantMonoidal` given instances are not used, and they do not match our type. Code fails when we have at least 2 instances of them
5
+ // Removal of `import catsSyntax._` allow to compile code
6
+ // Removal of `import odinSyntax.LoggerSyntax` and remaining `catsSyntax` would fail to compile the `def fails`
7
+
8
+ trait Foo [A ]
9
+ trait Bar [A ]
10
+
11
+ trait WriterT [F [_]: Contravariant , L , V ]:
12
+ def contramap [Z ](fn : Z => V ): WriterT [F , L , Z ] = ???
13
+ trait Logger [F [_]]
14
+ class WriterTLogger [F [_]] extends Logger [[G ] =>> WriterT [F , List [String ], G ]]
15
+
16
+ trait ContravariantMonoidal [F [_]] extends Invariant [F ] with Contravariant [F ]
17
+ trait Invariant [F [_]]
18
+ object Invariant :
19
+ given ContravariantMonoidal [Foo ] = ???
20
+ given ContravariantMonoidal [Bar ] = ???
21
+
22
+ trait Contravariant [F [_]] extends Invariant [F ]
23
+ object Contravariant :
24
+ trait Ops [F [_], A ]:
25
+ def contramap [B ](f : B => A ): F [B ] = ???
26
+
27
+ object catsSyntax :
28
+ implicit def toContravariantOps [F [_]: Contravariant , A ](target : F [A ]): Contravariant .Ops [F , A ] = ???
29
+
30
+ object odinSyntax :
31
+ implicit class LoggerSyntax [F [_]](logger : Logger [F ]):
32
+ def contramap (f : String => String ): Logger [F ] = ???
33
+
34
+ import catsSyntax ._
35
+ import odinSyntax .LoggerSyntax
36
+
37
+ class Test :
38
+ def fails = new WriterTLogger [Option ].contramap(identity)
39
+ def works = LoggerSyntax (new WriterTLogger [Option ]).contramap(identity)
You can’t perform that action at this time.
0 commit comments