Skip to content

Commit df96eba

Browse files
authored
Merge pull request #6037 from dotty-staging/remove-view-bounds
Remove view bounds
2 parents 4dd2f94 + 8440220 commit df96eba

File tree

13 files changed

+36
-34
lines changed

13 files changed

+36
-34
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,31 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
379379
* where <prefix> is the full name of the owner followed by a "." minus
380380
* the prefix "dotty.language.".
381381
*/
382-
def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
383-
val hasImport =
382+
def featureEnabled(feature: TermName, owner: Symbol = NoSymbol): Boolean = {
383+
def hasImport = {
384+
val owner1 = if (!owner.exists) defn.LanguageModuleClass else owner
384385
ctx.importInfo != null &&
385-
ctx.importInfo.featureImported(owner, feature)(ctx.withPhase(ctx.typerPhase))
386-
def hasOption = {
386+
ctx.importInfo.featureImported(feature, owner1)(ctx.withPhase(ctx.typerPhase))
387+
}
388+
val hasOption = {
387389
def toPrefix(sym: Symbol): String =
388-
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
390+
if (!sym.exists) ""
389391
else toPrefix(sym.owner) + sym.name + "."
390392
val featureName = toPrefix(owner) + feature
391393
ctx.base.settings.language.value exists (s => s == featureName || s == "_")
392394
}
393-
hasImport || hasOption
395+
hasOption || hasImport
394396
}
395397

396398
/** Is auto-tupling enabled? */
397399
def canAutoTuple: Boolean =
398-
!featureEnabled(defn.LanguageModuleClass, nme.noAutoTupling)
400+
!featureEnabled(nme.noAutoTupling)
399401

400402
def scala2Mode: Boolean =
401-
featureEnabled(defn.LanguageModuleClass, nme.Scala2)
403+
featureEnabled(nme.Scala2)
402404

403405
def dynamicsEnabled: Boolean =
404-
featureEnabled(defn.LanguageModuleClass, nme.dynamics)
406+
featureEnabled(nme.dynamics)
405407

406408
def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
407409
if (scala2Mode) {
@@ -414,7 +416,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
414416
/** Is option -language:Scala2 set?
415417
* This test is used when we are too early in the pipeline to consider imports.
416418
*/
417-
def scala2Setting = ctx.settings.language.value.contains(nme.Scala2.toString)
419+
def scala2Setting: Boolean =
420+
ctx.settings.language.value.contains(nme.Scala2.toString)
418421

419422
/** Refine child based on parent
420423
*

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ object Parsers {
296296
def deprecationWarning(msg: => Message, offset: Int = in.offset): Unit =
297297
ctx.deprecationWarning(msg, source.atSpan(Span(offset)))
298298

299+
def errorOrMigrationWarning(msg: => Message, offset: Int = in.offset): Unit =
300+
ctx.errorOrMigrationWarning(msg, source.atSpan(Span(offset)))
301+
299302
/** Issue an error at current offset that input is incomplete */
300303
def incompleteInputError(msg: => Message): Unit =
301304
ctx.incompleteInputError(msg, source.atSpan(Span(in.offset)))
@@ -1136,7 +1139,7 @@ object Parsers {
11361139
AppliedTypeTree(toplevelTyp(), Ident(pname))
11371140
} :: contextBounds(pname)
11381141
case VIEWBOUND =>
1139-
deprecationWarning("view bounds `<%' are deprecated, use a context bound `:' instead")
1142+
errorOrMigrationWarning("view bounds `<%' are deprecated, use a context bound `:' instead")
11401143
atSpan(in.skipToken()) {
11411144
Function(Ident(pname) :: Nil, toplevelTyp())
11421145
} :: contextBounds(pname)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ abstract class TokensCommon {
112112
//final val SUPERTYPE = 81; enter(SUPERTYPE, ">:")
113113
//final val HASH = 82; enter(HASH, "#")
114114
final val AT = 83; enter(AT, "@")
115-
//final val VIEWBOUND = 84; enter(VIEWBOUND, "<%") // TODO: deprecate
115+
//final val VIEWBOUND = 84; enter(VIEWBOUND, "<%")
116116

117117
val keywords: TokenSet
118118

@@ -194,7 +194,7 @@ object Tokens extends TokensCommon {
194194
final val SUBTYPE = 80; enter(SUBTYPE, "<:")
195195
final val SUPERTYPE = 81; enter(SUPERTYPE, ">:")
196196
final val HASH = 82; enter(HASH, "#")
197-
final val VIEWBOUND = 84; enter(VIEWBOUND, "<%") // TODO: deprecate
197+
final val VIEWBOUND = 84; enter(VIEWBOUND, "<%")
198198
final val QUOTE = 85; enter(QUOTE, "'")
199199

200200
/** XML mode */

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ trait Reporting { this: Context =>
6666
def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
6767
reportWarning(new FeatureWarning(msg, pos))
6868

69-
def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean,
69+
def featureWarning(feature: String, featureDescription: String,
7070
featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = {
7171
val req = if (required) "needs to" else "should"
72-
val prefix = if (isScala2Feature) "scala." else "dotty."
73-
val fqname = prefix + "language." + feature
72+
val fqname = s"scala.language.$feature"
7473

7574
val explain = {
7675
if (reporter.isReportedFeatureUseSite(featureUseSite)) ""

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ trait Checking {
623623
def checkImplicitConversionDefOK(sym: Symbol)(implicit ctx: Context): Unit = {
624624
def check(): Unit = {
625625
checkFeature(
626-
defn.LanguageModuleClass, nme.implicitConversions,
626+
nme.implicitConversions,
627627
i"Definition of implicit conversion $sym",
628628
ctx.owner.topLevelClass,
629629
sym.sourcePos)
@@ -660,20 +660,17 @@ trait Checking {
660660
defn.isPredefClass(conv.owner) ||
661661
conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
662662
if (!conversionOK)
663-
checkFeature(defn.LanguageModuleClass, nme.implicitConversions,
663+
checkFeature(nme.implicitConversions,
664664
i"Use of implicit conversion ${conv.showLocated}", NoSymbol, posd.sourcePos)
665665
}
666666

667667
/** Issue a feature warning if feature is not enabled */
668-
def checkFeature(base: ClassSymbol,
669-
name: TermName,
668+
def checkFeature(name: TermName,
670669
description: => String,
671670
featureUseSite: Symbol,
672671
pos: SourcePosition)(implicit ctx: Context): Unit =
673-
if (!ctx.featureEnabled(base, name))
674-
ctx.featureWarning(name.toString, description,
675-
isScala2Feature = base.isContainedIn(defn.LanguageModuleClass),
676-
featureUseSite, required = false, pos)
672+
if (!ctx.featureEnabled(name))
673+
ctx.featureWarning(name.toString, description, featureUseSite, required = false, pos)
677674

678675
/** Check that `tp` is a class type and that any top-level type arguments in this type
679676
* are feasible, i.e. that their lower bound conforms to their upper bound. If a type
@@ -1056,5 +1053,5 @@ trait NoChecking extends ReChecking {
10561053
override def checkNoForwardDependencies(vparams: List[ValDef])(implicit ctx: Context): Unit = ()
10571054
override def checkMembersOK(tp: Type, pos: SourcePosition)(implicit ctx: Context): Type = tp
10581055
override def checkInInlineContext(what: String, posd: Positioned)(implicit ctx: Context): Unit = ()
1059-
override def checkFeature(base: ClassSymbol, name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
1056+
override def checkFeature(name: TermName, description: => String, featureUseSite: Symbol, pos: SourcePosition)(implicit ctx: Context): Unit = ()
10601057
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ trait Implicits { self: Typer =>
947947

948948
private def strictEquality(implicit ctx: Context): Boolean =
949949
ctx.mode.is(Mode.StrictEquality) ||
950-
ctx.featureEnabled(defn.LanguageModuleClass, nme.strictEquality)
950+
ctx.featureEnabled(nme.strictEquality)
951951

952952
/** An Eql[T, U] instance is assumed
953953
* - if one of T, U is an error type, or

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
146146
private[this] var myUnimported: Symbol = _
147147

148148
/** Does this import clause or a preceding import clause import `owner.feature`? */
149-
def featureImported(owner: Symbol, feature: TermName)(implicit ctx: Context): Boolean = {
149+
def featureImported(feature: TermName, owner: Symbol)(implicit ctx: Context): Boolean = {
150150
def compute = {
151-
val isImportOwner = site.widen.typeSymbol `eq` owner
151+
val isImportOwner = site.widen.typeSymbol.eq(owner)
152152
if (isImportOwner && originals.contains(feature)) true
153153
else if (isImportOwner && excluded.contains(feature)) false
154154
else {
155155
var c = ctx.outer
156156
while (c.importInfo eq ctx.importInfo) c = c.outer
157-
(c.importInfo != null) && c.importInfo.featureImported(owner, feature)(c)
157+
(c.importInfo != null) && c.importInfo.featureImported(feature, owner)(c)
158158
}
159159
}
160160
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,7 @@ class Typer extends Namer
16951695
!ctx.dynamicsEnabled
16961696
if (reportDynamicInheritance) {
16971697
val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass))
1698-
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true,
1699-
cls, isRequired, cdef.sourcePos)
1698+
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", cls, isRequired, cdef.sourcePos)
17001699
}
17011700

17021701
checkNonCyclicInherited(cls.thisType, cls.classParents, cls.info.decls, cdef.posd)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CompilationTests extends ParallelTesting {
3434
// @Test // enable to test compileStdLib separately with detailed stats
3535
def compileStdLibOnly: Unit = {
3636
implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
37-
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
37+
compileList("compileStdLib", TestSources.stdLibSources, scala2Mode.and("-migration", "-Yno-inline"))
3838
}.checkCompile()
3939

4040
@Test def pos: Unit = {

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ NamedTypeArg ::= id ‘=’ Type
171171
NamedTypeArgs ::= ‘[’ NamedTypeArg {‘,’ NamedTypeArg} ‘]’ nts
172172
Refinement ::= ‘{’ [RefineDcl] {semi [RefineDcl]} ‘}’ ds
173173
SubtypeBounds ::= [‘>:’ Type] [‘<:’ Type] | INT TypeBoundsTree(lo, hi)
174-
TypeParamBounds ::= SubtypeBounds {‘<%’ Type} {‘:’ Type} ContextBounds(typeBounds, tps)
174+
TypeParamBounds ::= SubtypeBounds {‘:’ Type} ContextBounds(typeBounds, tps)
175175
```
176176

177177
### Expressions

library/src/scalaShadowing/language.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package scalaShadowing
3030
*
3131
* - [[Scala2 `Scala2`] backwards compatibility mode for Scala2
3232
* - [[noAtoTupling `noAutoTupling`]] disable auto-tupling
33+
* - [[strictEquality `strictEquality`]] enable strick equality
3334
*
3435
* @groupname production Language Features
3536
* @groupname experimental Experimental Language Features
@@ -217,6 +218,6 @@ object language {
217218
/** Where imported, auto-tupling is disabled */
218219
object noAutoTupling
219220

220-
/* Where imported loose equality using eqAny is disabled */
221+
/** Where imported loose equality using eqAny is disabled */
221222
object strictEquality
222223
}
File renamed without changes.

0 commit comments

Comments
 (0)