Skip to content

Commit 84a0197

Browse files
committed
Drop given parameter syntax
1 parent 82dbb9e commit 84a0197

File tree

39 files changed

+81
-109
lines changed

39 files changed

+81
-109
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ sealed trait CommunityProject:
4747
/** Is this project running in the test or update mode in the
4848
* context of the given suite? @see `run` for more details.
4949
*/
50-
final def isUpdateMode(given suite: CommunityBuildTest) =
50+
final def isUpdateMode(using suite: CommunityBuildTest) =
5151
suite.isInstanceOf[CommunityBuildUpdate]
5252

5353
/** Depending on the mode of operation, either
@@ -60,7 +60,7 @@ sealed trait CommunityProject:
6060
* and avoid network overhead. See https://github.com/lampepfl/dotty-drone
6161
* for more infrastructural details.
6262
*/
63-
final def run()(given suite: CommunityBuildTest) =
63+
final def run()(using suite: CommunityBuildTest) =
6464
val runCmd = if isUpdateMode then updateCommand else testCommand
6565
if !isUpdateMode then dependencies.foreach(_.publish())
6666
suite.test(project, binaryName, runCommandsArgs :+ runCmd)

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ object Parsers {
917917
def followingIsParamOrGivenType() =
918918
val lookahead = in.LookaheadScanner()
919919
lookahead.nextToken()
920-
if startParamOrGivenTypeTokens.contains(lookahead.token)
920+
if startParamTokens.contains(lookahead.token)
921921
|| lookahead.isIdent(nme.using)
922922
then true
923923
else if lookahead.token == IDENTIFIER then
@@ -1450,8 +1450,6 @@ object Parsers {
14501450
case MATCH => matchType(t)
14511451
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t
14521452
case _ =>
1453-
if (imods.isOneOf(GivenOrImplicit) && !t.isInstanceOf[FunctionWithMods])
1454-
syntaxError(ImplicitTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
14551453
if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods])
14561454
syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
14571455
t
@@ -2299,7 +2297,7 @@ object Parsers {
22992297
def parArgumentExprs(): (List[Tree], Boolean) = inParens {
23002298
if in.token == RPAREN then
23012299
(Nil, false)
2302-
else if in.token == GIVEN || isIdent(nme.using) then
2300+
else if isIdent(nme.using) then
23032301
in.nextToken()
23042302
(commaSeparated(argumentExpr), true)
23052303
else
@@ -2786,7 +2784,7 @@ object Parsers {
27862784
normalize(loop(start))
27872785
}
27882786

2789-
val funTypeArgMods: BitSet = BitSet(GIVEN, ERASED)
2787+
val funTypeArgMods: BitSet = BitSet(ERASED)
27902788

27912789
/** Wrap annotation or constructor in New(...).<init> */
27922790
def wrapNew(tpt: Tree): Select = Select(New(tpt), nme.CONSTRUCTOR)
@@ -2912,7 +2910,7 @@ object Parsers {
29122910
def paramMods() =
29132911
if in.token == IMPLICIT then addParamMod(() => Mod.Implicit())
29142912
else
2915-
if in.token == GIVEN || isIdent(nme.using) then addParamMod(() => Mod.Given())
2913+
if isIdent(nme.using) then addParamMod(() => Mod.Given())
29162914
if in.token == ERASED then addParamMod(() => Mod.Erased())
29172915

29182916
def param(): ValDef = {

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ object Tokens extends TokensCommon {
257257
AT, CASE)
258258

259259
final val canEndStatTokens: TokenSet = atomicExprTokens | BitSet(
260-
TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT)
260+
TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT) // TODO: remove GIVEN once old import syntax is dropped
261261

262262
/** Tokens that stop a lookahead scan search for a `<-`, `then`, or `do`.
263263
* Used for disambiguating between old and new syntax.
@@ -280,12 +280,6 @@ object Tokens extends TokensCommon {
280280
*/
281281
final val startParamTokens: BitSet = modifierTokens | BitSet(VAL, VAR, AT)
282282

283-
/** Faced with the choice of a type `(...)` or a parameter or given type list
284-
* in `(...)`, the following tokens after the opening `(` determine it's
285-
* a parameter or given type list.
286-
*/
287-
final val startParamOrGivenTypeTokens: BitSet = startParamTokens | BitSet(GIVEN, ERASED)
288-
289283
final val scala3keywords = BitSet(ENUM, ERASED, GIVEN)
290284

291285
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open)

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
150150
UnknownNamedEnclosingClassOrObjectID,
151151
IllegalCyclicTypeReferenceID,
152152
MissingTypeParameterInTypeAppID,
153-
ImplicitTypesCanOnlyBeFunctionTypesID,
153+
UNUSED_ImplicitTypesCanOnlyBeFunctionTypesID,
154154
ErasedTypesCanOnlyBeFunctionTypesID,
155155
CaseClassMissingNonImplicitParamListID,
156156
EnumerationsShouldNotBeEmptyID,

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,17 +2376,10 @@ object messages {
23762376
""".stripMargin
23772377
}
23782378

2379-
case class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(implicit val ctx: Context)
2380-
extends Message(IllegalCyclicTypeReferenceID) {
2381-
val kind: String = "Cyclic"
2382-
val msg: String = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself"
2383-
val explanation: String = ""
2384-
}
2385-
2386-
case class ImplicitTypesCanOnlyBeFunctionTypes()(implicit val ctx: Context) // TODO remove when (given ...) => is removed
2387-
extends Message(ImplicitTypesCanOnlyBeFunctionTypesID) {
2388-
val kind: String = "Syntax"
2389-
val msg: String = "Types with given keyword can only be function types `(given ...) => ...`"
2379+
case class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(implicit val ctx: Context)
2380+
extends Message(IllegalCyclicTypeReferenceID) {
2381+
val kind: String = "Cyclic"
2382+
val msg: String = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself"
23902383
val explanation: String = ""
23912384
}
23922385

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import java.nio.file.Paths
1717

1818
import PartialFunction.condOpt
1919

20-
import ast.untpd.given
21-
import NameOps.given
20+
import ast.untpd.{given _}
21+
import NameOps.{given _}
2222

2323
import scala.annotation.{ threadUnsafe => tu, tailrec }
2424

@@ -28,8 +28,8 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
2828
* TODO: Also extract type information
2929
*/
3030
class ExtractSemanticDB extends Phase with
31-
import Scala3.{_, given}
32-
import Symbols.given
31+
import Scala3.{_, given _}
32+
import Symbols.{given _}
3333

3434
override val phaseName: String = ExtractSemanticDB.name
3535

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ trait Applications extends Compatibility {
863863
new ApplyToTyped(tree, fun1, funRef, proto.typedArgs(), pt)
864864
else
865865
new ApplyToUntyped(tree, fun1, funRef, proto, pt)(
866-
given fun1.nullableInArgContext(using argCtx(tree)))
866+
using fun1.nullableInArgContext(using argCtx(tree)))
867867
convertNewGenericArray(
868868
postProcessByNameArgs(funRef, app.result).computeNullable())
869869
case _ =>

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ trait ImportSuggestions with
184184
try
185185
timer.schedule(task, testOneImplicitTimeOut)
186186
typedImplicit(candidate, expectedType, argument, span)(
187-
given ctx.fresh.setExploreTyperState()).isSuccess
187+
using ctx.fresh.setExploreTyperState()).isSuccess
188188
finally
189189
if task.cancel() then // timer task has not run yet
190190
assert(!ctx.run.isCancelled)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,8 @@ class Typer extends Namer
12321232

12331233
val pat1 = typedPattern(tree.pat, wideSelType)(gadtCtx)
12341234
caseRest(pat1)(
1235-
given Nullables.caseContext(sel, pat1)(
1236-
given gadtCtx.fresh.setNewScope))
1235+
using Nullables.caseContext(sel, pat1)(
1236+
using gadtCtx.fresh.setNewScope))
12371237
}
12381238

12391239
def typedLabeled(tree: untpd.Labeled)(implicit ctx: Context): Labeled = {
@@ -2345,7 +2345,7 @@ class Typer extends Namer
23452345
// in preceding statements (unless the DefTree is completed ahead of time,
23462346
// then it is impossible).
23472347
sym.info = Completer(completer.original)(
2348-
given completer.creationContext.withNotNullInfos(ctx.notNullInfos))
2348+
using completer.creationContext.withNotNullInfos(ctx.notNullInfos))
23492349
true
23502350
case _ =>
23512351
// If it has been completed, then it must be because there is a forward reference

compiler/test-resources/repl/defs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ scala> def id(x: 4): 4 = x
1010
def id(x: 4): 4
1111
scala> id(4)
1212
val res0: Int = 4
13-
scala> def f(given Int) = 1
14-
def f(given x$1: Int): Int
13+
scala> def f(using Int) = 1
14+
def f(using x$1: Int): Int

0 commit comments

Comments
 (0)