-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require array element types to be sealed
- Loading branch information
Showing
13 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,26 @@ | ||
-- Error: tests/neg-custom-args/captures/buffers.scala:11:6 ------------------------------------------------------------ | ||
11 | var elems: Array[A] = new Array[A](10) // error // error | ||
| ^ | ||
| mutable variable elems cannot have type Array[A] since | ||
| that type refers to the type variable A, which is not sealed. | ||
-- Error: tests/neg-custom-args/captures/buffers.scala:16:38 ----------------------------------------------------------- | ||
16 | def make[A: ClassTag](xs: A*) = new ArrayBuffer: // error | ||
| ^^^^^^^^^^^ | ||
| Sealed type variable A cannot be instantiated to box A^? since | ||
| that type refers to the type variable A, which is not sealed. | ||
| This is often caused by a local capability in an argument of constructor ArrayBuffer | ||
| leaking as part of its result. | ||
-- Error: tests/neg-custom-args/captures/buffers.scala:11:13 ----------------------------------------------------------- | ||
11 | var elems: Array[A] = new Array[A](10) // error // error | ||
| ^^^^^^^^ | ||
| Array cannot have element type A since | ||
| that type refers to the type variable A, which is not sealed. | ||
| Since arrays are mutable, they have to be treated like variables, | ||
| so their element type must be sealed. | ||
-- Error: tests/neg-custom-args/captures/buffers.scala:22:9 ------------------------------------------------------------ | ||
22 | val x: Array[A] = new Array[A](10) // error | ||
| ^^^^^^^^ | ||
| Array cannot have element type A since | ||
| that type refers to the type variable A, which is not sealed. | ||
| Since arrays are mutable, they have to be treated like variables, | ||
| so their element type must be sealed. |
This file contains 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,30 @@ | ||
import reflect.ClassTag | ||
|
||
class Buffer[A] | ||
|
||
class ArrayBuffer[sealed A: ClassTag] extends Buffer[A]: | ||
var elems: Array[A] = new Array[A](10) | ||
def add(x: A): this.type = ??? | ||
def at(i: Int): A = ??? | ||
|
||
class ArrayBufferBAD[A: ClassTag] extends Buffer[A]: | ||
var elems: Array[A] = new Array[A](10) // error // error | ||
def add(x: A): this.type = ??? | ||
def at(i: Int): A = ??? | ||
|
||
object ArrayBuffer: | ||
def make[A: ClassTag](xs: A*) = new ArrayBuffer: // error | ||
elems = xs.toArray | ||
def apply[sealed A: ClassTag](xs: A*) = new ArrayBuffer: | ||
elems = xs.toArray // ok | ||
|
||
class EncapsArray[A: ClassTag]: | ||
val x: Array[A] = new Array[A](10) // error | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains 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 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 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 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 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 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 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