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
Allow -_
and +_
as type names for -Xsource3
flag
#2348
Conversation
scalameta/dialects/shared/src/main/scala/scala/meta/dialects/package.scala
Outdated
Show resolved
Hide resolved
3aabc5f
to
a6dc868
Compare
scalameta/dialects/shared/src/main/scala/scala/meta/Dialect.scala
Outdated
Show resolved
Hide resolved
scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala
Outdated
Show resolved
Hide resolved
scalameta/dialects/shared/src/main/scala/scala/meta/dialects/package.scala
Outdated
Show resolved
Hide resolved
1c3bbdf
to
05c354a
Compare
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.
* works under -Xsource3 flag | ||
* https://github.com/scala/scala/pull/9605 | ||
*/ | ||
val allowPlusMinusUnderscoreIdent: Boolean |
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.
I would rename this. Looking at the scala code and doc, I'd call this allowUnderscoreAsTypeWildcard
and set to false in scala3 and scala2source3. the plus/minus thing is just a side effect because it needs co/contravariant types.
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.
We already have allowTypeParamUndesrcore
setting
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.
so why not use it? this is how it is described:
// Dotty rejects placeholder as Type parameter
val allowTypeParamUnderscore: Boolean,
yet it is never set to false anywhere and never used in parsing.
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.
I agree that this one fits better.
But in this case non Source3
scala2 dialects will accept this new syntax too.
Also, I forgot that we also need to enable allowTypeParamUnderscore
for scala3
@kitbellew @tgodzik are you ok with that?
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.
Oh. allowTypeParamUnderscore
is about different thing.
def f[_](a: Int): Int = ???
Ok, then the question is: are you ok to enable this syntax by default without any flag?
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.
Oh.
allowTypeParamUnderscore
is about different thing.def f[_](a: Int): Int = ???
Right, it's for a type parameter of a definition, not for a type definition. still, why can't i find any reads for allowTypeParamUnderscore
, and never false
for it?
Ok, then the question is: are you ok to enable this syntax by default without any flag?
allowUnderscoreAsTypeWildcard
(or whatever you decide to call it) shouldn't be part of scala213
.
i am thinking that we should implement some sort of reflection to allow a user to specify config
dialect {
base = scala213
options {
allowUnderscoreAsTypeWildcard = true
}
}
that way, we don't need to add it as part of any explicit dialect, we don't need scala213source3
either.
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.
Right, it's for a type parameter of a definition, not for a type definition. still, why can't i find any reads for allowTypeParamUnderscore, and never false for it?
It's used in several places. For example - here
What about setting rename. I decided to keep the existing one.
I looked on it one more time and as we currently always parse _
as Type.Placeholder
without any settings so the name you proposed doesn't fit for that.
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.
What about setting rename. I decided to keep the existing one.
I looked on it one more time and as we currently always parse_
asType.Placeholder
without any settings so the name you proposed doesn't fit for that.
Perhaps I should have been clearer. My proposal (with wildcards) would have had the opposite value; i.e., if you [still] allow wildcards, then it will not be parsed with +/-.
autoPos { | ||
accept[Ident] | ||
accept[Underscore] | ||
Type.Name(s"${ident.value}_") |
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.
should Type.Placeholder be subclassed or supplemented with Type.CovariantPlaceholder
and Type.ContravariantPlaceholder
and used here? after all, +_
is closer to a placeholder than an identifier, no?
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.
I thought about that. However, it's unclear if just a Name
or Placeholder
.
In Scala2 parser treat it as Name
and then if kind-projector is enabled it might be transformed into Placeholder
.
In Scala3 it will be Placeholder
. Are there any cons of having Placeholder
here?
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.
meaning, ignore the covariance (since, according to @neko-kai, it will be inferred) and just pretend it was a simple _
? maybe.
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.
@kitbellew In Scala 3 yes. In Scala 2 the variance is meaningful – I believe Scalameta should treat these exactly as it currently treats +*
/-*
/+?
/-?
kind projector placeholders right now – regarding the latter, Scala 3's -Ykind-projector
also treats +*
and -*
as if they're a simple _
as well – scala/scala3#12341
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.
Currently, scalameta parses kind-projector syntax (+*
/-*
/+?
/-?
) just as Type.Name
.
An additional thing here that we don't have variance mods for Type.Placeholder
.
I think the best option here would be to turn +_
, -_
into Type.Placeholder
for Scala3 and keep them as Type.Name
for Scala2*
.
@kitbellew @tgodzik wdyt?
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.
I think the best option here would be to turn
+_
,-_
intoType.Placeholder
for Scala3 and keep them asType.Name
forScala2*
.
sounds good
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.
👍
@@ -152,6 +154,7 @@ package object dialects { | |||
.withAllowStarWildcardImport(true) | |||
.withAllowProcedureSyntax(false) | |||
.withAllowDoWhile(false) | |||
.withAllowPlusMinusUnderscoreIdent(true) |
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.
should we start creating additional scala3 dialects? if we have lots of scala2.1x, why not scala3.1 and scala3.2?
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.
We will most likely need to, but currently I am not sure what will be in 3.1 at this point.
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.
we know that this flag we are adding is only in 3.2, right? at least according to the docs.
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.
@kitbellew The new syntax is already available under a flag -Ykind-projector:underscores
in 3.
See
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.
3.2 is when underscores will become the default syntax for type lambdas, without any flags. (+_
and -_
however will still be guarded by a flag, because they do not make sense for new code, only for cross-compilation, because now variance is inferred)
05c354a
to
d5fc267
Compare
for kind-projector that works under -Xsource3 flag.
d5fc267
to
55606a8
Compare
Summarizing all comments the final changeset is:
|
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.
LGTM!
if (dialect.allowPlusMinusUnderscoreAsPlaceholder) | ||
Type.Placeholder(typeBounds()) | ||
else | ||
Type.Name(s"${ident.value}_") |
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.
does this version not allow type bounds?
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.
yep, but it is in line with scala/scala#9605
Addresses #2347