-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Drop transparent
#9029
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
Comments
Is it possible to drop the wildcard as in |
The wildcard is needed for the |
Not sure about the second rule. We have to be careful with when widening types in inline val x = 1 // should be: val x: 1 = 1
inline val y: _ <: Int = 1 // should be: val y: 1 = 1
inline val z: Int = 1 // error With |
This is related to #8850. There we tried to use this same typing scheme for vals but using |
That was the previous syntax. It caused too much confusion in several situations. |
Shouldn't we have the following to align with the normal given syntax? inline given g as _ <: T = ...
inline given _ <: T = ... |
Maybe something like type Precise[T] <: T // magical type
inline def f: Precise[T] = ...
inline given g as Precise[T] = ... |
What about introduced type Refined[T] = T
inline given g as Refined[T] = ...
inline val x: Refined[Byte] = 1 |
@liufengyun @nicolasstucki The problem with normal types is that you then have to explain why these cannot be used in other places. One compromise would be to use inline given g as <:[T] = ...
inline val x: <:[Byte] = 1
inline def f(x: S): <:[T] = ... The But that might be even more surprising , so I am not sure it's better than |
|
What about regarding it as a generalization of type ascriptions? The typing rule for a type ascription expression is like the following:
If we introduce
We could introduce a short-hand for type Refined[T] = T @refined Updated: seen from the perspective of type ascriptions, it seems to suggest the following: e <: T // syntax for refinable type ascription
inline given g = e <: T
inline val x = 1 <: Byte
inline def f() = e <: T |
Could this be used as a general syntax for expressing "do not widen here"? This would solve the long-lasting issue of #3964 (and its predecessors #3920, #1262). trait Context {
type Tree
}
class Helper(val ctx: _ <: Context) {
def f(x: Int): ctx.Tree = ???
}
val ctx : Context = ???
val tree : ctx.Tree = new Helper(ctx).f(5) |
I probably missed a discussion somewhere, but what was the problem with directly writing |
After deliberating some more, I believe that `_ <: T` is the best alternative for expressing whitebox macros.
I'd like to go back from
transparent
to the earlier scheme where we used_ <: T
to indicate an upper bound for a result type. So it would befor whitebox macros. At the same time, I'd like to allow
_ <: T
as an upper bound of other result types as well. E.g.would produce a Byte constant, which was not possible before. Similarly, if we assume #9028,
f
would get typeB with C with D with Product
, so there's not need anymore to list all supertypes.The rules for this are straightforward
_ <: R
result type,R
is taken as the expected type of the right hand side.R
The text was updated successfully, but these errors were encountered: