diff options
author | Martin Odersky <odersky@gmail.com> | 2016-11-29 19:34:33 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-11-29 19:35:30 +0100 |
commit | e7a0d03f0d29b4644b09b0a36fb3557849d6cf72 (patch) | |
tree | 7094746ccadc200b14863a947f55e1a2fb170528 /compiler/src/dotty/tools/dotc/core/Definitions.scala | |
parent | f7001a4b6e83307cc8299b049cb23c79d004f0e2 (diff) | |
download | dotty-e7a0d03f0d29b4644b09b0a36fb3557849d6cf72.tar.gz dotty-e7a0d03f0d29b4644b09b0a36fb3557849d6cf72.tar.bz2 dotty-e7a0d03f0d29b4644b09b0a36fb3557849d6cf72.zip |
Create FunctionN types on demand
We know create FunctionN types on demand whenever their name
is looked up in the scope of package `scala`. This obviates
the need to predefine function traits 23 to 30.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/Definitions.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Definitions.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index f77d62eab..44f4acffa 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -767,6 +767,23 @@ class Definitions { // ----- Initialization --------------------------------------------------- + /** Give the scala package a scope where a FunctionN trait is automatically + * added when someone looks for it. + */ + private def makeScalaSpecial()(implicit ctx: Context) = { + val oldInfo = ScalaPackageClass.classInfo + val oldDecls = oldInfo.decls + val newDecls = new MutableScope(oldDecls) { + override def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry = { + val res = super.lookupEntry(name) + if (res == null && name.functionArity > 0) + newScopeEntry(newFunctionNTrait(name.functionArity)) + else res + } + } + ScalaPackageClass.info = oldInfo.derivedClassInfo(decls = newDecls) + } + /** Lists core classes that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */ lazy val syntheticScalaClasses = List( AnyClass, @@ -794,6 +811,8 @@ class Definitions { def init()(implicit ctx: Context) = { this.ctx = ctx if (!_isInitialized) { + makeScalaSpecial() + // force initialization of every symbol that is synthesized or hijacked by the compiler val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses() |