-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ignore all kinds of ProtoTypes instead of just AppliedProtos #6715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff844b5
Fix liftToClasses for opaque types
odersky db2390b
Revise liftToClasses to make CB work
odersky fae6009
drop redundant code
odersky 573b664
Ignore all kinds of ProtoTypes instead of just AppliedProtos
odersky 70535c8
Fix bug in error message
odersky 2881dee
Address review comments
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,7 @@ object Implicits { | |
*/ | ||
class OfTypeImplicits(tp: Type, val companionRefs: TermRefSet)(initctx: Context) extends ImplicitRefs(initctx) { | ||
assert(initctx.typer != null) | ||
implicits.println(i"implicits of type $tp = ${companionRefs.toList}%, %") | ||
@threadUnsafe lazy val refs: List[ImplicitRef] = { | ||
val buf = new mutable.ListBuffer[TermRef] | ||
for (companion <- companionRefs) buf ++= companion.implicitMembers(ImplicitOrImpliedOrGiven) | ||
|
@@ -491,13 +492,19 @@ trait ImplicitRunInfo { self: Run => | |
object liftToClasses extends TypeMap { | ||
override implicit protected val ctx: Context = liftingCtx | ||
override def stopAtStatic = true | ||
|
||
def apply(tp: Type) = tp match { | ||
case tp: TypeRef if !tp.symbol.isClass => | ||
val pre = tp.prefix | ||
def joinClass(tp: Type, cls: ClassSymbol) = | ||
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner)) | ||
val lead = if (pre eq NoPrefix) defn.AnyType else apply(pre) | ||
(lead /: tp.classSymbols)(joinClass) | ||
case tp: TypeRef => | ||
val sym = tp.symbol | ||
if (sym.isClass || sym.isOpaqueAlias) tp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same condition is repeated in the definition of |
||
else { | ||
val pre = tp.prefix | ||
def joinClass(tp: Type, cls: Symbol) = | ||
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner)) | ||
val lead = if (pre eq NoPrefix) defn.AnyType else apply(pre) | ||
def isLiftTarget(sym: Symbol) = sym.isClass || sym.isOpaqueAlias | ||
(lead /: tp.parentSymbols(isLiftTarget))(joinClass) | ||
} | ||
case tp: TypeVar => | ||
apply(tp.underlying) | ||
case tp: AppliedType if !tp.tycon.typeSymbol.isClass => | ||
|
@@ -516,7 +523,7 @@ trait ImplicitRunInfo { self: Run => | |
|
||
// todo: compute implicits directly, without going via companionRefs? | ||
def collectCompanions(tp: Type): TermRefSet = track("computeImplicitScope") { | ||
trace(i"collectCompanions($tp)", implicits) { | ||
trace(i"collectCompanions($tp)", implicitsDetailed) { | ||
|
||
def iscopeRefs(t: Type): TermRefSet = implicitScopeCache.get(t) match { | ||
case Some(is) => | ||
|
@@ -575,8 +582,10 @@ trait ImplicitRunInfo { self: Run => | |
def computeIScope() = { | ||
val liftedTp = if (isLifted) tp else liftToClasses(tp) | ||
val refs = | ||
if (liftedTp ne tp) | ||
if (liftedTp ne tp) { | ||
implicitsDetailed.println(i"lifted of $tp = $liftedTp") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken indentation. |
||
iscope(liftedTp, isLifted = true).companionRefs | ||
} | ||
else | ||
collectCompanions(tp) | ||
val result = new OfTypeImplicits(tp, refs)(ctx) | ||
|
@@ -673,7 +682,7 @@ trait Implicits { self: Typer => | |
} | ||
|
||
/** Synthesize the tree for `'[T]` for an implicit `scala.quoted.Type[T]`. | ||
* `T` is deeply dealiassed to avoid references to local type aliases. | ||
* `T` is deeply dealiased to avoid references to local type aliases. | ||
*/ | ||
lazy val synthesizedTypeTag: SpecialHandler = | ||
(formal, span) => implicit ctx => { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
object A { | ||
|
||
object opaques { | ||
opaque type FlagSet = Long | ||
def FlagSet(bits: Long): FlagSet = bits.asInstanceOf // !!! | ||
def toBits(fs: FlagSet): Long = fs | ||
} | ||
val someFlag = FlagSet(1) | ||
type FlagSet = opaques.FlagSet | ||
def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) | ||
|
||
delegate FlagOps { | ||
def (xs: FlagSet) bits: Long = opaques.toBits(xs) | ||
def (xs: FlagSet) | (ys: FlagSet): FlagSet = FlagSet(xs.bits | ys.bits) | ||
} | ||
} | ||
|
||
object B { | ||
type Variance = A.FlagSet | ||
|
||
val f: A.FlagSet = A.someFlag | ||
f.bits // OK | ||
|
||
val v: Variance = A.someFlag | ||
v.bits // OK, used to fail with: value bits is not a member of B.Variance | ||
|
||
A.someFlag.bits // OK | ||
var x = 0 | ||
(if (x > 0) A.someFlag else A.someFlag).bits // OK, used to fail with: value bits is not a member of ? | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect "ignored version" to mean "IgnoredProto" but we always map to WildcardType instead, so maybe the documentation should read: