-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #876: Allow implicit conversions from singleton types #4738
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
Changes from 1 commit
bd04177
4721da5
d3cd401
69bfb34
5728b19
c8d9b0d
673af1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,17 +71,20 @@ object Implicits { | |
| /** The implicit references */ | ||
| def refs: List[ImplicitRef] | ||
|
|
||
| private var SingletonClass: ClassSymbol = null | ||
|
Member
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. Why add a cache for SingletonClass?
Contributor
Author
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. Same reason as for the caches in TypeComparer. It's used a lot and as a lazy val access is not super fast. It was one of the performance tweaks I applied after we saw a slip. Not sure it was the one that made the difference. |
||
|
|
||
| /** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */ | ||
| private def widenSingleton(tp: Type)(implicit ctx: Context): Type = { | ||
| if (SingletonClass == null) SingletonClass = defn.SingletonClass | ||
| val wtp = tp.widenSingleton | ||
| if (wtp.derivesFrom(SingletonClass)) defn.AnyType else wtp | ||
| } | ||
|
|
||
| /** Return those references in `refs` that are compatible with type `pt`. */ | ||
| protected def filterMatching(pt: Type)(implicit ctx: Context): List[Candidate] = track("filterMatching") { | ||
|
|
||
| def refMatches(ref: TermRef)(implicit ctx: Context) = /*trace(i"refMatches $ref $pt")*/ { | ||
|
|
||
| /** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */ | ||
| def widenSingleton(tp: Type): Type = { | ||
| val wtp = tp.widenSingleton | ||
| if (wtp.derivesFrom(defn.SingletonClass)) defn.AnyType else wtp | ||
| } | ||
|
|
||
| def discardForView(tpw: Type, argType: Type): Boolean = tpw match { | ||
| case mt: MethodType => | ||
| mt.isImplicitMethod || | ||
|
|
@@ -150,7 +153,7 @@ object Implicits { | |
| val res = adjustSingletonArg(tp.resType) | ||
| if (res `eq` tp.resType) tp else tp.derivedLambdaType(resType = res) | ||
| case tp: MethodType => | ||
| tp.derivedLambdaType(paramInfos = tp.paramInfos.map(widenSingleton)) | ||
| tp.derivedLambdaType(paramInfos = tp.paramInfos.mapConserve(widenSingleton)) | ||
| case _ => tp | ||
| } | ||
|
|
||
|
|
||
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.
private[this]to avoid generating accessors?