-
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
Fix #9482: simplified Manifest synthesis #13142
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
14 changes: 14 additions & 0 deletions
14
tests/neg-custom-args/deprecation/manifest-summoning.check
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,14 @@ | ||
-- Error: tests/neg-custom-args/deprecation/manifest-summoning.scala:1:34 ---------------------------------------------- | ||
1 |val foo = manifest[List[? <: Int]] // error | ||
| ^ | ||
| Compiler synthesis of Manifest and OptManifest is deprecated, instead | ||
| replace with the type `scala.reflect.ClassTag[List[? <: Int]]`. | ||
| Alternatively, consider using the new metaprogramming features of Scala 3, | ||
| see https://docs.scala-lang.org/scala3/reference/metaprogramming.html | ||
-- Error: tests/neg-custom-args/deprecation/manifest-summoning.scala:2:41 ---------------------------------------------- | ||
2 |val bar = optManifest[Array[? <: String]] // error | ||
| ^ | ||
| Compiler synthesis of Manifest and OptManifest is deprecated, instead | ||
| replace with the type `scala.reflect.ClassTag[Array[? <: String]]`. | ||
| Alternatively, consider using the new metaprogramming features of Scala 3, | ||
| see https://docs.scala-lang.org/scala3/reference/metaprogramming.html |
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,2 @@ | ||
val foo = manifest[List[? <: Int]] // error | ||
val bar = optManifest[Array[? <: String]] // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
val `Array[Nothing]` = manifest[Array[Nothing]] // error | ||
val `Array[Null]` = manifest[Array[Null]] // error | ||
val m_Nothing = manifest[Nothing] // error | ||
val m_Null = manifest[Null] // error | ||
|
||
val `Array[? <: Nothing]` = manifest[Array[? <: Nothing]] // error | ||
val `Array[? <: Null]` = manifest[Array[? <: Null]] // error | ||
|
||
val `Int @unchecked` = manifest[Int @unchecked] // error | ||
|
||
val `0 | 1` = manifest[0 | 1] // error | ||
|
||
class Box[T] { | ||
val m = manifest[T] // error | ||
} | ||
|
||
object Foo { | ||
type F[T] <: T | ||
manifest[Array[F[Int]]] // error | ||
} | ||
|
||
object opaques { | ||
opaque type OpaqueList[+A] = List[A] | ||
} | ||
import opaques.* | ||
|
||
val `OpaqueList[Int]` = manifest[OpaqueList[Int]] // error (opaque types are not supported) |
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,11 @@ | ||
import scala.reflect.OptManifest | ||
|
||
object Ref { | ||
def make[A: OptManifest]: Ref[A] = ??? | ||
} | ||
trait Ref[A] | ||
|
||
trait Foo[A] { | ||
val bar = Ref.make[Int] | ||
val baz: Ref[A] = Ref.make | ||
} |
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,22 @@ | ||
object Foo { | ||
|
||
object opaques { | ||
opaque type Inner = String | ||
val i: Inner = "i" | ||
} | ||
|
||
val singleton: opaques.Inner = opaques.i | ||
|
||
val om_Inner = optManifest[opaques.Inner] // NoManifest | ||
val om_singleton = optManifest[singleton.type] // NoManifest | ||
val ct_Inner = reflect.classTag[opaques.Inner] | ||
val ct_singleton = reflect.classTag[singleton.type] | ||
} | ||
|
||
val `List[Nothing]` = manifest[List[Nothing]] | ||
val `List[Array[Nothing]]` = manifest[List[Array[Nothing]]] // ok when Nothing is not the argument of top-level array | ||
|
||
val `Array[Array[List[Int]]]` = manifest[Array[Array[List[Int]]]] | ||
|
||
trait Mixin[T <: Mixin[T]] { type Self = T } | ||
class Baz extends Mixin[Baz] { val m = manifest[Self] } |
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,83 @@ | ||
import scala.reflect.{OptManifest, ClassTag} | ||
|
||
object Ref { | ||
|
||
object Sentinel | ||
|
||
def makeWithArr[A: OptManifest]: String = optManifest[A] match { | ||
case m: ClassTag[_] => m.newArray(0).asInstanceOf[AnyRef] match { | ||
// these can be reordered, so long as Unit comes before AnyRef | ||
case _: Array[Boolean] => "bool" | ||
case _: Array[Byte] => "byte" | ||
case _: Array[Short] => "short" | ||
case _: Array[Char] => "char" | ||
case _: Array[Int] => "int" | ||
case _: Array[Float] => "float" | ||
case _: Array[Long] => "long" | ||
case _: Array[Double] => "double" | ||
case _: Array[Unit] => "unit" | ||
case a: Array[AnyRef] => a.getClass.getComponentType.getName | ||
} | ||
case _ => "<?>" | ||
} | ||
|
||
def make[A: OptManifest]: String = optManifest[A] match { | ||
case m: ClassTag[a] => m match { | ||
case ClassTag.Boolean => "bool" | ||
case ClassTag.Byte => "byte" | ||
case ClassTag.Short => "short" | ||
case ClassTag.Char => "char" | ||
case ClassTag.Int => "int" | ||
case ClassTag.Float => "float" | ||
case ClassTag.Long => "long" | ||
case ClassTag.Double => "double" | ||
case ClassTag.Unit => "unit" | ||
case ClassTag.Any => "any" | ||
case ClassTag.AnyVal => "anyval" | ||
case ClassTag.Object => "anyref" | ||
case _ => m.runtimeClass.getName | ||
} | ||
case NoManifest => "<?>" | ||
} | ||
|
||
} | ||
|
||
import Ref.* | ||
|
||
def baz[A] = Ref.makeWithArr[A] | ||
def qux[A] = Ref.make[A] | ||
|
||
@main def Test = { | ||
|
||
assert(Ref.makeWithArr[Boolean] == "bool") | ||
assert(Ref.makeWithArr[Byte] == "byte") | ||
assert(Ref.makeWithArr[Short] == "short") | ||
assert(Ref.makeWithArr[Char] == "char") | ||
assert(Ref.makeWithArr[Int] == "int") | ||
assert(Ref.makeWithArr[Float] == "float") | ||
assert(Ref.makeWithArr[Long] == "long") | ||
assert(Ref.makeWithArr[Double] == "double") | ||
assert(Ref.makeWithArr[Unit] == "unit") | ||
assert(Ref.makeWithArr["abc"] == "java.lang.String") | ||
assert(Ref.makeWithArr[Null] == "<?>") | ||
assert(Ref.makeWithArr[Nothing] == "<?>") | ||
assert(baz[Int] == "<?>") | ||
|
||
assert(Ref.make[Boolean] == "bool") | ||
assert(Ref.make[Byte] == "byte") | ||
assert(Ref.make[Short] == "short") | ||
assert(Ref.make[Char] == "char") | ||
assert(Ref.make[Int] == "int") | ||
assert(Ref.make[Float] == "float") | ||
assert(Ref.make[Long] == "long") | ||
assert(Ref.make[Double] == "double") | ||
assert(Ref.make[Unit] == "unit") | ||
assert(Ref.make[Any] == "any") | ||
assert(Ref.make[AnyVal] == "anyval") | ||
assert(Ref.make[AnyRef] == "anyref") | ||
assert(Ref.make["abc"] == "java.lang.String") | ||
assert(Ref.make[Null] == "<?>") | ||
assert(Ref.make[Nothing] == "<?>") | ||
assert(qux[Int] == "<?>") | ||
|
||
} |
Oops, something went wrong.
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.
Seems like this method could be used to solve #13131 :)