From d43618a92cef21f4d4bb921b61d319eb358eae29 Mon Sep 17 00:00:00 2001 From: François Garillot Date: Thu, 19 Dec 2013 15:15:07 +0100 Subject: SI-8126 Add a '-Xsource' flag allowing compilation in e.g. 2.10 mode This is aimed at letting the 2.11+ compiler operate, at least until phase:typer, on a 2.10 codebase. --- .../scala/tools/nsc/settings/ScalaSettings.scala | 79 ++++++++++++---------- 1 file changed, 43 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 6ec364bcb6..307f42c0bc 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -73,48 +73,55 @@ trait ScalaSettings extends AbsScalaSettings val nospecialization = BooleanSetting ("-no-specialization", "Ignore @specialize annotations.") val language = MultiStringSetting("-language", "feature", "Enable one or more language features.") + /* + * The previous "-source" option is intended to be used mainly + * though this helper. + */ + lazy val isScala211: Boolean = (source.value >= ScalaVersion("2.11.0")) + /** * -X "Advanced" settings */ - val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options.") - val checkInit = BooleanSetting ("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.") - val developer = BooleanSetting ("-Xdev", "Indicates user is a developer - issue warnings about anything which seems amiss") - val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.") - val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument", + val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options.") + val checkInit = BooleanSetting ("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.") + val developer = BooleanSetting ("-Xdev", "Indicates user is a developer - issue warnings about anything which seems amiss") + val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.") + val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument", elidable.MINIMUM, None, elidable.byName get _) - val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes.") - val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot.", "") - val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more detail on why some implicits are not applicable.") - val logImplicitConv = BooleanSetting ("-Xlog-implicit-conversions", "Print a message whenever an implicit conversion is inserted.") - val logReflectiveCalls = BooleanSetting("-Xlog-reflective-calls", "Print a message when a reflective method call is generated") - val logFreeTerms = BooleanSetting ("-Xlog-free-terms", "Print a message when reification creates a free term.") - val logFreeTypes = BooleanSetting ("-Xlog-free-types", "Print a message when reification resorts to generating a free type.") - val maxClassfileName = IntSetting ("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, Some((72, 255)), _ => None) - val Xmigration = ScalaVersionSetting("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", AnyScalaVersion) - val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.") - val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.") - val Xverify = BooleanSetting ("-Xverify", "Verify generic signatures in generated bytecode (asm backend only.)") - val plugin = MultiStringSetting("-Xplugin", "paths", "Load a plugin from each classpath.") - val disable = MultiStringSetting("-Xplugin-disable", "plugin", "Disable plugins by name.") - val showPlugins = BooleanSetting ("-Xplugin-list", "Print a synopsis of loaded plugins.") - val require = MultiStringSetting("-Xplugin-require", "plugin", "Abort if a named plugin is not loaded.") - val pluginsDir = StringSetting ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath) - val Xprint = PhasesSetting ("-Xprint", "Print out program after") - val writeICode = PhasesSetting ("-Xprint-icode", "Log internal icode to *.icode files after", "icode") - val Xprintpos = BooleanSetting ("-Xprint-pos", "Print tree positions, as offsets.") - val printtypes = BooleanSetting ("-Xprint-types", "Print tree types (debugging option).") - val prompt = BooleanSetting ("-Xprompt", "Display a prompt after each error (debugging option).") - val resident = BooleanSetting ("-Xresident", "Compiler stays resident: read source filenames from standard input.") - val script = StringSetting ("-Xscript", "object", "Treat the source file as a script and wrap it in a main method.", "") - val mainClass = StringSetting ("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d )", "") - val Xshowcls = StringSetting ("-Xshow-class", "class", "Show internal representation of class.", "") - val Xshowobj = StringSetting ("-Xshow-object", "object", "Show internal representation of object.", "") - val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases.") - val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") - val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types") + val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes.") + val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot.", "") + val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more detail on why some implicits are not applicable.") + val logImplicitConv = BooleanSetting ("-Xlog-implicit-conversions", "Print a message whenever an implicit conversion is inserted.") + val logReflectiveCalls = BooleanSetting ("-Xlog-reflective-calls", "Print a message when a reflective method call is generated") + val logFreeTerms = BooleanSetting ("-Xlog-free-terms", "Print a message when reification creates a free term.") + val logFreeTypes = BooleanSetting ("-Xlog-free-types", "Print a message when reification resorts to generating a free type.") + val maxClassfileName = IntSetting ("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, Some((72, 255)), _ => None) + val Xmigration = ScalaVersionSetting ("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", AnyScalaVersion) + val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.") + val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.") + val Xverify = BooleanSetting ("-Xverify", "Verify generic signatures in generated bytecode (asm backend only.)") + val plugin = MultiStringSetting ("-Xplugin", "paths", "Load a plugin from each classpath.") + val disable = MultiStringSetting ("-Xplugin-disable", "plugin", "Disable plugins by name.") + val showPlugins = BooleanSetting ("-Xplugin-list", "Print a synopsis of loaded plugins.") + val require = MultiStringSetting ("-Xplugin-require", "plugin", "Abort if a named plugin is not loaded.") + val pluginsDir = StringSetting ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath) + val Xprint = PhasesSetting ("-Xprint", "Print out program after") + val writeICode = PhasesSetting ("-Xprint-icode", "Log internal icode to *.icode files after", "icode") + val Xprintpos = BooleanSetting ("-Xprint-pos", "Print tree positions, as offsets.") + val printtypes = BooleanSetting ("-Xprint-types", "Print tree types (debugging option).") + val prompt = BooleanSetting ("-Xprompt", "Display a prompt after each error (debugging option).") + val resident = BooleanSetting ("-Xresident", "Compiler stays resident: read source filenames from standard input.") + val script = StringSetting ("-Xscript", "object", "Treat the source file as a script and wrap it in a main method.", "") + val mainClass = StringSetting ("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d )", "") + val Xshowcls = StringSetting ("-Xshow-class", "class", "Show internal representation of class.", "") + val Xshowobj = StringSetting ("-Xshow-object", "object", "Show internal representation of object.", "") + val showPhases = BooleanSetting ("-Xshow-phases", "Print a synopsis of compiler phases.") + val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "") + val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types") + val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see SI-8126.", ScalaVersion("2.11")) withPostSetHook ( _ => isScala211) val XnoPatmatAnalysis = BooleanSetting ("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.") - val XfullLubs = BooleanSetting ("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.") + val XfullLubs = BooleanSetting ("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.") /** Compatibility stubs for options whose value name did * not previously match the option name. -- cgit v1.2.3 From 6dd3653b9c443170492eba63be542440496d0432 Mon Sep 17 00:00:00 2001 From: François Garillot Date: Thu, 19 Dec 2013 15:23:06 +0100 Subject: SI-8126 Puts SI-6899 fix under a source level flag --- src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 19fba639e3..06a1e21e8b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1365,7 +1365,7 @@ trait Implicits { maybeInvalidConversionError("the result type of an implicit conversion must be more specific than AnyRef") result = SearchFailure } - else if (isInvalidConversionSource(pt)) { + else if (settings.isScala211 && isInvalidConversionSource(pt)) { maybeInvalidConversionError("an expression of type Null is ineligible for implicit conversion") result = SearchFailure } -- cgit v1.2.3 From 94e05a85013df444badef0c8b00503d71408ed08 Mon Sep 17 00:00:00 2001 From: François Garillot Date: Thu, 19 Dec 2013 15:27:01 +0100 Subject: SI-8126 Puts SI-7335 fix behind a source level flag --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 6b5afce993..5d0d5392dd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1793,7 +1793,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val impl2 = finishMethodSynthesis(impl1, clazz, context) - if (mdef.symbol == PredefModule) + if (settings.isScala211 && mdef.symbol == PredefModule) ensurePredefParentsAreInSameSourceFile(impl2) // SI-5954. On second compile of a companion class contained in a package object we end up -- cgit v1.2.3