Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Wildcard *value* #49

Open
OlivierBlanvillain opened this issue Jun 12, 2019 · 1 comment
Open

Wildcard *value* #49

OlivierBlanvillain opened this issue Jun 12, 2019 · 1 comment

Comments

@OlivierBlanvillain
Copy link

Currently we still have underscore as wildcard for default values:

var i: Int = _          // i = 0
var s: String = _    // s = null

Can we have a wildcard value, besides the wildcard type we just implemented? Something like

var i: Int = ?          // i = 0
var s: String = ?    // s = null
var a: Any = ?       // indeterminate type
var av: AnyVal = ?       // indeterminate type
var d: Double = av      // determined as type specified, d = 0.0
var ar: AnyRef = ?       // indeterminate type
var foo: Foo = ar         // determined as type specified,  foo = null: Foo
def bar[T]: T = ?          // generic 
var bar1 = bar[Any]    // bar1: Any = ? indeterminate type
var bar2 = bar[Double] // bar2: Double = 0.0

and broaden the use of this syntax to local variables as well (currently it only works for class field)

Originally posted by @texasbruce in scala/scala3#5379 (comment)

@neontorrent
Copy link

Thanks for creating a FR. This is also related to the existing issue scala/bug#1470 in that Scala does not have a default value for Any and AnyVal:

scala> new Array[AnyVal](2)   
res0: Array[AnyVal] = Array(null, null)

This is incorrect because null is not AnyVal. When we have the wildcard value, we will be able to achieve something like:

scala> new Array[AnyVal](2)   
res0: Array[AnyVal] = Array(?, ?)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants