So that we can deprecate the following language features / stdlib members:
What's the plan for implicit object X extends Y -- will that be allowed? I seem to recall it not being as good as a precise type.
Good question. I think these are fine because we just write their type as the corresponding singleton type without requiring further inference. This rule aims to avoid triggering inference during implicit search, which is thus always ok for objects. Will have to experiment a bit more to convince myself though :)
What's the deal with "implicit val/def without complete signature"? I have been recently following IntelliJ's advise to add return types for implicit vals, but this produces a quite unfortunate situation, illustrated by the following examples:
before
implicit val auralContext = AuralContext[S](server, scheduler)
implicit val system = InMemory()
implicit val undo = UndoManager()
after
implicit val auralContext: AuralContext[S] = AuralContext(server, scheduler)
implicit val system: InMemory = InMemory()
implicit val undo: UndoManager = UndoManager()
etc.
May I propose that a type annotation _be not required_ if we call either new Type or call apply on the companion object such as Type()? If so, where would I discuss and eventually propose this rule?
I think that would strike a good balance between still essentially documenting the type and avoiding Java'ish DRY horror.
See https://github.com/lampepfl/dotty/issues/2879, where @smarter indicates that:
Dotty does reduce the boilerplate a bit by desugaring:
val x: Foo[Bar] = new { ... }To:
val x: Foo[Bar] = new Foo[Bar] { ... }
@dwijnand Ok, but that leaves Companion.apply which in my experience is far more common...
Explicit types for implicit vals should only be required for field vals. Local vals (inside defs) are allowed not to have an explicit type.
@sjrd thanks for the clarification; I will then petition IntelliJ to rethink their default inspection which indeed produces unneeded verbosity :)
No need for an over-arching ticket on this anymore. scala-rewrites is a thing (and published!) and we can and will add things when they come up.
Most helpful comment
Explicit types for implicit vals should only be required for field
vals. Localvals (insidedefs) are allowed not to have an explicit type.