-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow named tuple syntax for case class constructors. #22400
base: main
Are you sure you want to change the base?
Conversation
A test case that shows that we can have an "inline type class" that allows to use a typeclass-based scheme for sequence literals where instances can be created with macros.
Also: Move test to run
We now don't try to instantiate selected type variables. Instead, we use a default as fallback if the expected type is underspecified according to the definition in Implicits. This is simpler and more expressive.
Also, test infix operations taking [...] as a right operand.
This is a tweak to the named tuple spec. If the expected type is a case class expand to a call of its apply method.
val anotherLit: IArray[Double] = [math.Pi, math.cos(2.0), math.E * 3.0] | ||
val diag: Array[Array[Int]] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] | ||
val empty: ArrayBuffer[Object] = [] | ||
val mapy: HashMap[Int, String] = [1 -> "one", 2 -> "two", 3 -> "three"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I more like Dartlang's syntax for this, here, []
is an Array, which makes me think the KEY can be REPEATED, but actually, it isn't.
val mapy: HashMap[Int, String] = [1 -> "one", 2 -> "two", 3 -> "three"]
can be
val mapy: Array[(Int, String)] = [1 -> "one", 2 -> "two", 3 -> "three"]
but if you chose Dart's syntax, then the HashMap[Int, String]
can be omitted.
val mapy = {1 -> "one", 2 -> "two", 3 -> "three"}
is a map or
val mapy = {1 : "one", 2 : "two", 3 :"three"}
is a map too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When all are []
, you lose the information of if the element or key can be repeated, and then you have to annotate the result type explicitly, which is not how Scala's works, a well static typed language as a dynamic language, and now, with []
everywhere, we are writing plain old Java
.
This is a tweak to the named tuple spec and implementation. If the expected type is a case class,
expand a named tuple to a call of the apply method of the case class.
Based on #21993. Only the last commit is relevant.