lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Make repeated arguments for sequence argument type annotation inline-able at Compile Time #239

Closed yuriy-yarosh closed 1 year ago

yuriy-yarosh commented 3 years ago

Right now I'm a bit tired of being unable to use Repeated Argument Type Notation like so

case class R(a: Boolean, b: Boolean, c: Boolean = true)
val params = Seq(true, true, true)
R(params: _*)

It would be great for dotty to be able to inline Repeated Arguments in compile time and take into account the resulted gaps in the actual call expression.

It would also be wise to restrict this inlining notation for Compile Time Usage Only, because it will be misused at Runtime and will cause a lot of headache.

This kind of notation has a huge impact on table driven testing and protocol definitions. (Developing a http/3 QUIC related project right now).

Thus my frames defs look like so

enum Frame(typeValue: Byte,
           name: String,
           initial: Boolean = false, // I
           handshake: Boolean = false, // H
           RTT0: Boolean = false, // 0-RTT
           RTT1: Boolean = false, // 1-RTT
           notAckEliciting: Boolean = false, // N
           doNotCountForCongestion: Boolean = false, // C
           networkProbing: Boolean = false, // P
           flowControlled: Boolean = false // F
):
  case Padding extends Frame(0x00, "PADDING", true, true, true, true, notAckEliciting = true, networkProbing = true)
  case Ping extends Frame(0x01, "PING", true, true, true, true)
  case Ack2 extends Frame(0x02, "ACK", true, true, false, true, notAckEliciting = true, doNotCountForCongestion = true)
  case Ack3 extends Frame(0x03, "ACK", true, true, false, true, notAckEliciting = true, doNotCountForCongestion = true)
  ....
end Frame

object Frame:
  private[quic] val RTTOnly = Seq(false, false, true, true)
end Frame

And it would be great if I could refactor such tables with more readable constructs like

case StopSending extends Frame(0x05, "STOP_SENDING", Frame.RTTOnly:_*) 

For now I'm using scala staging to overcome this limitation, which isn't great.