Keep type refinements without the use of `Selectable`

Hi All,

I really like using structural types for type level programming and was pretty disappointed that they’re now very annoying to use despite not using runtime reflection or applyDynamic/selectDynamic.

It would be great if we could still use type refinements (mainly for type level programming) without the boilerplate repetition of ascribing the types we just defined. Type inference is a key selling feature of scala, and it’s a shame to go backwards in this area compared to scala 2.

I’d like to see this brought back for Scala 3 without requiring the use of Selectable where only type members are needed.

I raised this here in dotty feature requests but this is probably a better place for discussion


1 Like

It’s only an issue when you add a new type member to the refinement. Not when you refine an existing type member.

trait Refined { type Bar }

val foo0 = new Refined {
  type Bar = String
val foobar0: foo0.Bar = "I work"

val foo1 = new Object {
  type Bar = String
val foobar1: foo1.Bar = "I don't work"

In my experience usually when doing type level programming you do the first one.
However I don’t really have a strong opinion on why you would not want to allow the second one.