Skip to content

Commit bf5107d

Browse files
committed
Use implicit instead of implied for instance definitions
`implied` is supported as well for now, in order to the bootstrap to proceed. Will be removed once everyone changed to `implicit`.
1 parent de3581c commit bf5107d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+229
-223
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,6 @@ object SymDenotations {
18781878
throw ex
18791879
}
18801880

1881-
18821881
/*>|>*/ trace.onDebug(s"$tp.baseType($this)") /*<|<*/ {
18831882
Stats.record("baseTypeOf")
18841883
recur(tp)

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ object Parsers {
193193
/** Is current token a hard or soft modifier (in modifier position or not)? */
194194
def isModifier: Boolean = modifierTokens.contains(in.token) || in.isSoftModifier
195195

196-
def isBindingIntro: Boolean =
197-
canStartBindingTokens.contains(in.token) &&
198-
!in.isSoftModifierInModifierPosition
196+
def isBindingIntro: Boolean = {
197+
in.token match {
198+
case USCORE | LPAREN => true
199+
case IDENTIFIER | BACKQUOTED_IDENT => in.lookaheadIn(BitSet(COLON, ARROW))
200+
case _ => false
201+
}
202+
} && !in.isSoftModifierInModifierPosition
199203

200204
def isExprIntro: Boolean =
201205
canStartExpressionTokens.contains(in.token) &&
@@ -2267,12 +2271,12 @@ object Parsers {
22672271

22682272
type ImportConstr = (Boolean, Tree, List[Tree]) => Tree
22692273

2270-
/** Import ::= import [implied] [ImportExpr {`,' ImportExpr}
2271-
* Export ::= export [implied] [ImportExpr {`,' ImportExpr}
2274+
/** Import ::= import [implicit] [ImportExpr {`,' ImportExpr}
2275+
* Export ::= export [implicit] [ImportExpr {`,' ImportExpr}
22722276
*/
22732277
def importClause(leading: Token, mkTree: ImportConstr): List[Tree] = {
22742278
val offset = accept(leading)
2275-
val importImplied = in.token == IMPLIED
2279+
val importImplied = in.token == IMPLICIT || in.token == IMPLIED
22762280
if (importImplied) in.nextToken()
22772281
commaSeparated(importExpr(importImplied, mkTree)) match {
22782282
case t :: rest =>
@@ -2582,10 +2586,16 @@ object Parsers {
25822586
case ENUM =>
25832587
enumDef(start, mods, atSpan(in.skipToken()) { Mod.Enum() })
25842588
case IMPLIED =>
2585-
instanceDef(start, mods, atSpan(in.skipToken()) { Mod.Instance() })
2589+
instanceDef(start, addMod(mods, atSpan(in.skipToken()) { Mod.Instance() }))
25862590
case _ =>
2587-
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
2588-
EmptyTree
2591+
mods.mods.lastOption match {
2592+
case Some(impl @ Mod.Implicit()) =>
2593+
val strippedMods = mods.withFlags(mods.flags &~ Implicit).withMods(mods.mods.init)
2594+
instanceDef(start, addMod(strippedMods, Mod.Instance().withSpan(impl.span)))
2595+
case _ =>
2596+
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
2597+
EmptyTree
2598+
}
25892599
}
25902600
}
25912601

@@ -2683,8 +2693,8 @@ object Parsers {
26832693
* InstanceBody ::= [‘for’ ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
26842694
* | ‘for’ Type {GivenParamClause} ‘=’ Expr
26852695
*/
2686-
def instanceDef(start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) {
2687-
var mods1 = addMod(mods, instanceMod)
2696+
def instanceDef(start: Offset, mods: Modifiers) = atSpan(start, nameStart) {
2697+
var mods1 = mods
26882698
val name = if (isIdent) ident() else EmptyTermName
26892699
val tparams = typeParamClauseOpt(ParamOwner.Def)
26902700
val parents =
@@ -2981,9 +2991,9 @@ object Parsers {
29812991
}
29822992
}
29832993

2984-
/** BlockStatSeq ::= { BlockStat semi } [ResultExpr]
2994+
/** BlockStatSeq ::= { BlockStat semi } [Expr]
29852995
* BlockStat ::= Import
2986-
* | Annotations [implicit] [lazy] Def
2996+
* | Annotations [implicit] [lazy] [erased] Def
29872997
* | Annotations LocalModifiers TmplDef
29882998
* | Expr1
29892999
* |
@@ -3005,13 +3015,12 @@ object Parsers {
30053015
var imods = modifiers(closureMods)
30063016
if (isBindingIntro)
30073017
stats += implicitClosure(start, Location.InBlock, imods)
3008-
else if (in.token == MATCH)
3018+
else if (in.token == MATCH && imods.mods == Mod.Implicit() :: Nil)
30093019
stats += implicitMatch(start, imods)
30103020
else
30113021
stats +++= localDef(start, imods)
3012-
} else {
3013-
stats +++= localDef(in.offset)
30143022
}
3023+
else stats +++= localDef(in.offset)
30153024
else if (!isStatSep && (in.token != CASE)) {
30163025
exitOnError = mustStartStat
30173026
syntaxErrorOrIncomplete(IllegalStartOfStatement(isModifier))

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ object Tokens extends TokensCommon {
178178
final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate
179179
final val ENUM = 62; enter(ENUM, "enum")
180180
final val ERASED = 63; enter(ERASED, "erased")
181-
final val IMPLIED = 64; enter(IMPLIED, "implied")
181+
final val IMPLIED = 64; enter(IMPLIED, "implied") // FIXME: remove
182182
final val GIVEN = 65; enter(GIVEN, "given")
183183
final val EXPORT = 66; enter(EXPORT, "export")
184184
final val MACRO = 67; enter(MACRO, "macro") // TODO: remove
@@ -219,8 +219,6 @@ object Tokens extends TokensCommon {
219219
final val canStartTypeTokens: TokenSet = literalTokens | identifierTokens | BitSet(
220220
THIS, SUPER, USCORE, LPAREN, AT)
221221

222-
final val canStartBindingTokens: TokenSet = identifierTokens | BitSet(USCORE, LPAREN)
223-
224222
final val templateIntroTokens: TokenSet = BitSet(CLASS, TRAIT, OBJECT, ENUM, CASECLASS, CASEOBJECT)
225223

226224
final val dclIntroTokens: TokenSet = BitSet(DEF, VAL, VAR, TYPE, IMPLIED)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ class Namer { typer: Typer =>
949949

950950
def whyNoForwarder(mbr: SingleDenotation): String = {
951951
val sym = mbr.symbol
952-
if (sym.is(ImplicitOrImplied) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied"
952+
if (sym.is(ImplicitOrImplied) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implicit"
953953
else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible"
954954
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP
955955
else if (cls.derivesFrom(sym.owner) &&

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ReplCompilerTests extends ReplTest {
129129
}
130130

131131
@Test def i5897 =
132-
fromInitialState { implicit state => run("implied for Int = 10") }
132+
fromInitialState { implicit state => run("implicit for Int = 10") }
133133
.andThen { implicit state =>
134134
assertEquals(
135135
"def Int_instance: Int",
@@ -151,7 +151,7 @@ class ReplCompilerTests extends ReplTest {
151151
| def (x: T) > (y: T) = compare(x, y) > 0
152152
|}
153153
|
154-
|implied IntOrd for Ord[Int] {
154+
|implicit IntOrd for Ord[Int] {
155155
| def compare(x: Int, y: Int) =
156156
| if (x < y) -1 else if (x > y) +1 else 0
157157
|}

tests/neg-custom-args/conditionalWarnings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
object Test {
44
@deprecated def foo = ???
55

6-
implied for Conversion[String, Int] = _.length
6+
implicit for Conversion[String, Int] = _.length
77

88
foo // error
99

tests/neg-custom-args/implicit-conversions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ class B
33

44
object A {
55

6-
implied for Conversion[A, B] {
6+
implicit for Conversion[A, B] {
77
def apply(x: A): B = ???
88
}
99

10-
implied for Conversion[B, A] {
10+
implicit for Conversion[B, A] {
1111
def apply(x: B): A = ???
1212
}
1313
}
1414

1515
class C
1616

1717
object D {
18-
implied for Conversion[A, C] {
18+
implicit for Conversion[A, C] {
1919
def apply(x: A): C = ???
2020
}
2121
}
2222

2323
object Test {
24-
import implied D._
24+
import implicit D._
2525

2626
val x1: A = new B
2727
val x2: B = new A // error under -Xfatal-warnings -feature

tests/neg/derive-eq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
case class One() derives Eql
33
case class Two() derives Eql
44

5-
implied for Eql[One, Two] = Eql.derived
5+
implicit for Eql[One, Two] = Eql.derived
66

77
enum Lst[T] derives Eql {
88
case Cons(x: T, xs: Lst[T])

tests/neg/exports.check

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
<1150..1150> in exports.scala
1+
<1152..1152> in exports.scala
22
Cyclic reference involving value bar
3-
[1091..1094] in exports.scala
3+
[1093..1096] in exports.scala
44
no eligible member foo at this.foo
55
this.foo.foo cannot be exported because it is already a member of class Foo
6-
[991..997] in exports.scala
6+
[993..999] in exports.scala
77
no eligible member concat at this
88
this.concat cannot be exported because it is already a member of trait IterableOps
9-
<647..647> in exports.scala
9+
<648..648> in exports.scala
1010
Double definition:
1111
final def status: => List[String] in class Copier at line 23 and
1212
final def status: => List[String] in class Copier at line 24
1313
have the same type after erasure.
14-
<596..596> in exports.scala
14+
<597..597> in exports.scala
1515
Double definition:
1616
def status: => List[String] in class Copier at line 28 and
1717
final def status: => List[String] in class Copier at line 23
1818
have the same type after erasure.
19-
[785..791] in exports.scala
19+
[787..793] in exports.scala
2020
no eligible member status at this.printUnit
21-
this.printUnit.status cannot be exported because it is not implied
22-
[712..718] in exports.scala
21+
this.printUnit.status cannot be exported because it is not implicit
22+
[713..719] in exports.scala
2323
no eligible member bitmap at this.printUnit
24-
this.printUnit.bitmap cannot be exported because it is implied
25-
[518..525] in exports.scala
24+
this.printUnit.bitmap cannot be exported because it is implicit
25+
[519..526] in exports.scala
2626
no eligible member scanAll at this.scanUnit
2727
this.scanUnit.scanAll cannot be exported because it is not accessible
28-
[452..458] in exports.scala
28+
[453..459] in exports.scala
2929
no eligible member scanIt at this.scanUnit

tests/neg/exports.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
type PrinterType
66
def print(bits: BitMap): Unit = ???
77
def status: List[String] = ???
8-
implied bitmap for BitMap
8+
implicit bitmap for BitMap
99
}
1010

1111
class Scanner {
@@ -23,7 +23,7 @@
2323
export printUnit.{stat => _, _} // error: double definition
2424
export scanUnit._ // error: double definition
2525
export printUnit.bitmap // error: no eligible member
26-
export implied printUnit.status // error: no eligible member
26+
export implicit printUnit.status // error: no eligible member
2727

2828
def status: List[String] = printUnit.status ++ scanUnit.status
2929
}

0 commit comments

Comments
 (0)