Skip to content

Commit b536711

Browse files
committed
Specify GivenVal where appropriate
Be more specific whether we specify a given or implicit val, or whether a class is also OK. This prepares the way for merging GivenClass and Given.
1 parent 98a3f9c commit b536711

File tree

9 files changed

+10
-11
lines changed

9 files changed

+10
-11
lines changed

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
6363
private def nestedScopeCtx(defs: List[Tree])(using Context): Context = {
6464
val nestedCtx = ctx.fresh.setNewScope
6565
defs foreach {
66-
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol)
66+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) => nestedCtx.enter(d.symbol)
6767
case _ =>
6868
}
6969
nestedCtx
@@ -74,7 +74,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
7474
new TreeTraverser {
7575
def traverse(tree: Tree)(using Context): Unit = {
7676
tree match {
77-
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) =>
77+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) =>
7878
nestedCtx.enter(d.symbol)
7979
case _ =>
8080
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Scopes._
1313
import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
16-
import Flags.GivenOrImplicit
1716
import util.{NoSource, SimpleIdentityMap, SourceFile, HashSet, ReusableInstance}
1817
import typer.{Implicits, ImportInfo, Inliner, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
1918
import Nullables._

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ object Flags {
321321
val (Extension @ _, ExtensionMethod @ _, _) = newFlags(28, "<extension>")
322322

323323
/** An inferable (`given`) parameter */
324-
val (Given @ _, _, _) = newFlags(29, "given")
324+
val (Given @ _, GivenVal @ _, GivenType @ _) = newFlags(29, "given")
325325

326326
/** Symbol is defined by a Java class */
327327
val (JavaDefined @ _, JavaDefinedVal @ _, _) = newFlags(30, "<java>")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ object Scopes {
411411
var irefs = new mutable.ListBuffer[TermRef]
412412
var e = lastEntry
413413
while (e ne null) {
414-
if (e.sym.isOneOf(GivenOrImplicit)) {
414+
if (e.sym.isOneOf(GivenOrImplicitVal)) {
415415
val d = e.sym.denot
416416
irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d)
417417
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ object SymDenotations {
22442244
if (keepOnly eq implicitFilter)
22452245
if (this.is(Package)) Iterator.empty
22462246
// implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation`
2247-
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicit))
2247+
else info.decls.iterator.filter(_.isOneOf(GivenOrImplicitVal))
22482248
else info.decls.iterator
22492249
for (sym <- ownSyms) maybeAdd(sym.name)
22502250
names

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError {
141141
}
142142

143143
// Give up and give generic errors.
144-
else if (cycleSym.isOneOf(GivenOrImplicit, butNot = Method) && cycleSym.owner.isTerm)
144+
else if (cycleSym.isOneOf(GivenOrImplicitVal, butNot = Method) && cycleSym.owner.isTerm)
145145
CyclicReferenceInvolvingImplicit(cycleSym)
146146
else
147147
CyclicReferenceInvolving(denot)

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ object Completion {
322322
val extMethodsFromImplicitScope = extractMemberExtensionMethods(implicitScopeCompanions)
323323

324324
// 4. The reference is of the form r.m and the extension method is defined in some given instance in the implicit scope of the type of r.
325-
val givensInImplicitScope = implicitScopeCompanions.flatMap(_.membersBasedOnFlags(required = Given, excluded = EmptyFlags)).map(_.info)
325+
val givensInImplicitScope = implicitScopeCompanions.flatMap(_.membersBasedOnFlags(required = GivenVal, excluded = EmptyFlags)).map(_.info)
326326
val extMethodsFromGivensInImplicitScope = extractMemberExtensionMethods(givensInImplicitScope)
327327

328328
val availableExtMethods = extMethodsFromGivensInImplicitScope ++ extMethodsFromImplicitScope ++ extMethodsFromGivensInScope ++ extMethodsInScope

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ trait Applications extends Compatibility {
16281628
/** Widen the result type of synthetic given methods from the implementation class to the
16291629
* type that's implemented. Example
16301630
*
1631-
* given I[X] as T { ... }
1631+
* given I[X]: T with { ... }
16321632
*
16331633
* This desugars to
16341634
*
@@ -1638,7 +1638,7 @@ trait Applications extends Compatibility {
16381638
* To compare specificity we should compare with `T`, not with its implementation `I[X]`.
16391639
* No such widening is performed for given aliases, which are not synthetic. E.g.
16401640
*
1641-
* given J[X] as T = rhs
1641+
* given J[X]: T = rhs
16421642
*
16431643
* already has the right result type `T`. Neither is widening performed for given
16441644
* objects, since these are anyway taken to be more specific than methods

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class ImportInfo(symf: Context ?=> Symbol,
151151
else
152152
for
153153
renamed <- reverseMapping.keys
154-
denot <- pre.member(reverseMapping(renamed)).altsWith(_.isOneOf(GivenOrImplicit))
154+
denot <- pre.member(reverseMapping(renamed)).altsWith(_.isOneOf(GivenOrImplicitVal))
155155
yield
156156
val original = reverseMapping(renamed)
157157
val ref = TermRef(pre, original, denot)

0 commit comments

Comments
 (0)