diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-01-10 22:36:30 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2017-01-28 19:12:19 +0100 |
commit | dc5ba9d2ba31b2fe27f5b967c9fb800bc9210a93 (patch) | |
tree | 3fe1a54e734a97fc6a999a695a7e1141cff6d460 /compiler | |
parent | 779c96bef04d81048f91135b386bd7f37fcf1f20 (diff) | |
download | dotty-dc5ba9d2ba31b2fe27f5b967c9fb800bc9210a93.tar.gz dotty-dc5ba9d2ba31b2fe27f5b967c9fb800bc9210a93.tar.bz2 dotty-dc5ba9d2ba31b2fe27f5b967c9fb800bc9210a93.zip |
Workaroud #1856: recursively calling a lazy val works differently in Dotty
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Definitions.scala | 12 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/ImportInfo.scala | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 134b31519..0aeb28d36 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -319,7 +319,17 @@ class Definitions { def staticsMethodRef(name: PreName) = ScalaStaticsModule.requiredMethodRef(name) def staticsMethod(name: PreName) = ScalaStaticsModule.requiredMethod(name) - lazy val DottyPredefModuleRef = ctx.requiredModuleRef("dotty.DottyPredef") + // Dotty deviation: we cannot use a lazy val here because lazy vals in dotty + // will return "null" when called recursively, see #1856. + def DottyPredefModuleRef = { + if (myDottyPredefModuleRef == null) { + myDottyPredefModuleRef = ctx.requiredModuleRef("dotty.DottyPredef") + assert(myDottyPredefModuleRef != null) + } + myDottyPredefModuleRef + } + private[this] var myDottyPredefModuleRef: TermRef = _ + def DottyPredefModule(implicit ctx: Context) = DottyPredefModuleRef.symbol def Predef_eqAny(implicit ctx: Context) = DottyPredefModule.requiredMethod(nme.eqAny) diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index a5657890e..f7efb2ac2 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -30,7 +30,16 @@ object ImportInfo { class ImportInfo(symf: => Symbol, val selectors: List[untpd.Tree], symNameOpt: Option[TermName], val isRootImport: Boolean = false)(implicit ctx: Context) { - lazy val sym = symf + // Dotty deviation: we cannot use a lazy val here for the same reason + // that we cannot use one for `DottyPredefModuleRef`. + def sym = { + if (mySym == null) { + mySym = symf + assert(mySym != null) + } + mySym + } + private[this] var mySym: Symbol = _ /** The (TermRef) type of the qualifier of the import clause */ def site(implicit ctx: Context): Type = { |