Lazy can't see through public -> private type aliases
See original GitHub issueJava: OpenJDK 1.8.0_202 Scala: 2.12.4 shapeless: 2.3.3
Minimal reproduction: I believe all four cases shown below should compile, but only the first three do. The fourth fails because Lazy
seems to lose the detailed knowledge of NonEmptyChain[String]
(but works in the simple case where the first type parameter case is just String
).
trait TC[F[_]]
type ValidatedString[A] = cats.data.Validated[String, A]
type ValidatedNecString[A] = cats.data.Validated[NonEmptyChain[String], A]
{
implicit def mkTypeClass[F[_]](implicit F: cats.Functor[F]): TC[F] = ???
implicitly[TC[ValidatedString]] // works
implicitly[TC[ValidatedNecString]] // works
}
{
implicit def mkTypeClassLazy[F[_]](implicit F: Lazy[cats.Functor[F]]): TC[F] = ???
implicitly[TC[ValidatedString]] // works
implicitly[TC[ValidatedNecString]] // doesn't compile
}
I’ve had a look through related tickets but I don’t think this is covered elsewhere.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Tracking issue for RFC 2515, "Permit impl Trait in type aliases"
One syntactic impl Trait gives you one opaque type; making an alias for it and using it in multiple places does not change...
Read more >Lazy var giving 'Instance member can not be used on type' error
Try that : class SomeClass { var coreDataStuff = CoreDataStuff! lazy var somethingElse: SomethingElse = SomethingElse(coreDataStuff: self.coreDataStuff) }.
Read more >Opaque Type Aliases: More Details - Scala 3 - EPFL
Opaque type aliases cannot be private and cannot be overridden in subclasses. Opaque type aliases cannot have a context function type as right-hand...
Read more >Lazy Computations in Java with a Lazy Type - SitePoint
But before looking at this, we must first implement type laziness. ... private String message; public String getMessage() { if (message ...
Read more >Entity types with constructors - EF Core - Microsoft Learn
The constructor can be public, private, or have any other ... field and makes it clear that it should not be set explicitly...
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 Free
Top 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
Thanks all for your input on this. Agreed, it seems like it’s not something shapeless can reasonably fix, so I’m happy for you to close. The workaround (for now at least) is to explicitly re-import the necessary implicits.
It also seems like there are other issues cats with newtypes, so I will comment there and link back to this issue.
It’s possible that a bit less dealiasing in the
Lazy
macro might help, but even if it did it would be very fragile.I think it’s a mistake to rely on constructions which depend on aliases having different properties from their alisees (IOW, I think this is a problem with the newtype implementation) … we should have referential transparency at the type level as well as the term level.
I’ll leave this open for a bit, but I’m inclined to close it.