-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix array creation v2 #254
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dotty.runtime | ||
|
||
import scala.reflect.ClassTag | ||
|
||
/** All but the first operation should be short-circuited and implemented specially by | ||
* the backend. | ||
*/ | ||
object Arrays { | ||
|
||
/** Creates an array of some element type determined by the given `ClassTag` | ||
* argument. The erased type of applications of this method is `Object`. | ||
*/ | ||
def newGenericArray[T](length: Int)(implicit tag: ClassTag[T]): Array[T] = | ||
tag.newArray(length) | ||
|
||
/** Create an array of type T. T must be of form Array[E], with | ||
* E being a reference type. | ||
*/ | ||
def newRefArray[T](length: Int): T = ??? | ||
|
||
/** Create a Byte[] array */ | ||
def newByteArray(length: Int): Array[Byte] = ??? | ||
|
||
/** Create a Short[] array */ | ||
def newShortArray(length: Int): Array[Short] = ??? | ||
|
||
/** Create a Char[] array */ | ||
def newCharArray(length: Int): Array[Char] = ??? | ||
|
||
/** Create an Int[] array */ | ||
def newIntArray(length: Int): Array[Int] = ??? | ||
|
||
/** Create a Long[] array */ | ||
def newLongArray(length: Int): Array[Long] = ??? | ||
|
||
/** Create a Float[] array */ | ||
def newFloatArray(length: Int): Array[Float] = ??? | ||
|
||
/** Create a Double[] array */ | ||
def newDoubleArray(length: Int): Array[Double] = ??? | ||
|
||
/** Create a Boolean[] array */ | ||
def newBooleanArray(length: Int): Array[Boolean] = ??? | ||
|
||
/** Create a scala.runtime.BoxedUnit[] array */ | ||
def newUnitArray(length: Int): Array[Unit] = ??? | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
object Test { | ||
val w = new Array[String](10) | ||
val x = new Array[Int](10) | ||
def f[T: reflect.ClassTag] = new Array[T](10) | ||
val y = new Array[Any](10) | ||
val z = new Array[Unit](10) | ||
} | ||
object Test2 { | ||
val w: Array[String] = new Array(10) | ||
val x: Array[Int] = new Array(10) | ||
def f[T: reflect.ClassTag]: Array[T] = new Array(10) | ||
val y: Array[Any] = new Array(10) | ||
val z: Array[Unit] = new Array(10) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is return type T instead of Array[T] here intentional?
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.
From the comment: "
T
must be of formArray[E]
". So yes, I suppose it is intentional.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.
Yes, that's intentional. It's a technically to fit best with the way erasure works for polymorphic functions. That way, we can treat newRefArray and asInstanceOf in exactly the same way.