Skip to content

Commit 60d1c2d

Browse files
committed
Update given syntax in compiler and library (2)
1 parent 0d570f3 commit 60d1c2d

File tree

3 files changed

+15
-33
lines changed

3 files changed

+15
-33
lines changed

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
942942
private case object NoTypeTest extends RTTypeTest
943943

944944
private object RTTypeTest {
945-
given PartialOrdering[RTTypeTest] {
945+
given PartialOrdering[RTTypeTest] with {
946946
override def tryCompare(lhs: RTTypeTest, rhs: RTTypeTest): Option[Int] = {
947947
if (lteq(lhs, rhs)) if (lteq(rhs, lhs)) Some(0) else Some(-1)
948948
else if (lteq(rhs, lhs)) Some(1) else None

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ object Parsers {
913913
lookahead.nextToken()
914914
skipParams()
915915
skipParams()
916-
lookahead.token == COLON || lookahead.isIdent(nme.as)
916+
lookahead.token == COLON
917917

918918
def followingIsExtension() =
919919
val next = in.lookahead.token
@@ -3517,9 +3517,8 @@ object Parsers {
35173517
*/
35183518
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
35193519
var mods1 = addMod(mods, givenMod)
3520-
val hasGivenSig = followingIsGivenSig()
35213520
val nameStart = in.offset
3522-
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
3521+
val name = if isIdent && followingIsGivenSig() then ident() else EmptyTermName
35233522

35243523
val gdef =
35253524
val tparams = typeParamClauseOpt(ParamOwner.Def)
@@ -3530,10 +3529,7 @@ object Parsers {
35303529
else Nil
35313530
newLinesOpt()
35323531
val noParams = tparams.isEmpty && vparamss.isEmpty
3533-
val newSyntax = in.token == COLON
3534-
if !(name.isEmpty && noParams) then
3535-
if isIdent(nme.as) then in.nextToken()
3536-
else accept(COLON)
3532+
if !(name.isEmpty && noParams) then accept(COLON)
35373533
val parents = constrApp() :: withConstrApps()
35383534
val parentsIsType = parents.length == 1 && parents.head.isType
35393535
if in.token == EQUALS && parentsIsType then
@@ -3544,22 +3540,16 @@ object Parsers {
35443540
ValDef(name, parents.head, subExpr())
35453541
else
35463542
DefDef(name, tparams, vparamss, parents.head, subExpr())
3547-
else if newSyntax && in.token != WITH && in.token != WITHEOL && parentsIsType then
3543+
else if in.token != WITH && in.token != WITHEOL && parentsIsType then
35483544
if name.isEmpty then
35493545
syntaxError(em"anonymous given cannot be abstract")
35503546
DefDef(name, tparams, vparamss, parents.head, EmptyTree)
35513547
else
35523548
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
35533549
val vparamss1 = vparamss.map(_.map(vparam =>
35543550
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected)))
3555-
val constr = makeConstructor(tparams1, vparamss1)
3556-
val templ =
3557-
if newSyntax || in.token == WITHEOL || in.token == WITH then
3558-
withTemplate(constr, parents)
3559-
else
3560-
possibleTemplateStart()
3561-
templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3562-
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3551+
val templ = withTemplate(makeConstructor(tparams1, vparamss1), parents)
3552+
if noParams then ModuleDef(name, templ)
35633553
else TypeDef(name.toTypeName, templ)
35643554
end gdef
35653555
finalizeDef(gdef, mods1, start)

library/src/scala/util/CommandLineParser.scala

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,28 @@ object CommandLineParser {
5454
}
5555

5656
object FromString {
57-
given FromString[String] {
57+
given FromString[String] with
5858
def fromString(s: String) = s
59-
}
6059

61-
given FromString[Boolean] {
60+
given FromString[Boolean] with
6261
def fromString(s: String) = s.toBoolean
63-
}
6462

65-
given FromString[Byte] {
63+
given FromString[Byte] with
6664
def fromString(s: String) = s.toByte
67-
}
6865

69-
given FromString[Short] {
66+
given FromString[Short] with
7067
def fromString(s: String) = s.toShort
71-
}
7268

73-
given FromString[Int] {
69+
given FromString[Int] with
7470
def fromString(s: String) = s.toInt
75-
}
7671

77-
given FromString[Long] {
72+
given FromString[Long] with
7873
def fromString(s: String) = s.toLong
79-
}
8074

81-
given FromString[Float] {
75+
given FromString[Float] with
8276
def fromString(s: String) = s.toFloat
83-
}
8477

85-
given FromString[Double] {
78+
given FromString[Double] with
8679
def fromString(s: String) = s.toDouble
87-
}
8880
}
8981
}

0 commit comments

Comments
 (0)