diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index ec8effd02567..e594a64affec 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -570,7 +570,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo { .setTyper(new Typer) .addMode(Mode.ImplicitsEnabled) .setTyperState(ctx.typerState.fresh(ctx.reporter)) - if ctx.settings.YexplicitNulls.value && !Feature.enabledBySetting(nme.unsafeNulls) then + if ctx.settings.YexplicitNulls.value || Feature.enabledBySetting(nme.safeNulls) then start = start.addMode(Mode.SafeNulls) ctx.initialize()(using start) // re-initialize the base context with start diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index 69042935824b..8617d38618f1 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -59,6 +59,7 @@ object Feature: (nme.noAutoTupling, "Disable automatic tupling"), (nme.dynamics, "Allow direct or indirect subclasses of scala.Dynamic"), (nme.unsafeNulls, "Enable unsafe nulls for explicit nulls"), + (nme.safeNulls, "Enable safe nulls for explicit nulls"), (nme.postfixOps, "Allow postfix operators (not recommended)"), (nme.strictEquality, "Enable strict equality (disable canEqualAny)"), (nme.implicitConversions, "Allow implicit conversions without warnings"), diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 705ec36c286a..7796ff1bf73b 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -466,7 +466,8 @@ private sealed trait YSettings: // Experimental language features @deprecated(message = "This flag has no effect and will be removed in a future version.", since = "3.7.0") val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism. (This flag has no effect)", deprecation = Deprecation.removed()) - val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.") + val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Since explicit nulls is enabled by default, this flag now enables safe nulls for explicit-nulls") + val YnoExplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-explicit-nulls", "Make reference types implictly nullable.") val YnoFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-flexible-types", "Disable turning nullable Java return types and parameter types into flexible types, which behave like abstract types with a nullable lower bound and non-nullable upper bound.") val YflexifyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yflexify-tasty", "Apply flexification to Scala code compiled without -Yexplicit-nulls, when reading from tasty.") val YsafeInitGlobal: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init-global", "Check safe initialization of global objects.") @@ -482,6 +483,7 @@ private sealed trait YSettings: val YexplainLowlevel: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplain-lowlevel", "When explaining type errors, show types at a lower level.") val YnoDoubleBindings: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-double-bindings", "Assert no namedtype is bound twice (should be enabled only if program is error-free).") val YshowVarBounds: Setting[Boolean] = BooleanSetting(ForkSetting, "Yshow-var-bounds", "Print type variables with their bounds.") + val YhideFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yhide-flexible-types", "Print flexible types as their base type. (T instead of (T)?)") val Yinstrument: Setting[Boolean] = BooleanSetting(ForkSetting, "Yinstrument", "Add instrumentation code that counts allocations and closure creations.") val YinstrumentDefs: Setting[Boolean] = BooleanSetting(ForkSetting, "Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.") diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 471721338b96..ca05b3670639 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -484,13 +484,13 @@ object Contexts { fresh.setSetting(ctx.settings.color, "never") /** Is the explicit nulls option set? */ - def explicitNulls: Boolean = base.settings.YexplicitNulls.value + def explicitNulls: Boolean = !base.settings.YnoExplicitNulls.value /** Is the flexible types option set? */ - def flexibleTypes: Boolean = base.settings.YexplicitNulls.value && !base.settings.YnoFlexibleTypes.value + def flexibleTypes: Boolean = explicitNulls && !base.settings.YnoFlexibleTypes.value /** Is the flexify tasty option set? */ - def flexifyTasty: Boolean = base.settings.YexplicitNulls.value && base.settings.YflexifyTasty.value + def flexifyTasty: Boolean = explicitNulls && base.settings.YflexifyTasty.value /** Is the best-effort option set? */ def isBestEffort: Boolean = base.settings.YbestEffort.value @@ -730,7 +730,9 @@ object Contexts { importInfo.mentionsFeature(nme.unsafeNulls) match case Some(true) => setMode(this.mode &~ Mode.SafeNulls) - case Some(false) if ctx.settings.YexplicitNulls.value => + case _ => + importInfo.mentionsFeature(nme.safeNulls) match + case Some(true) if explicitNulls => setMode(this.mode | Mode.SafeNulls) case _ => updateStore(importInfoLoc, importInfo) diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index 34fa92c220fc..73d5ca3558d8 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -658,6 +658,7 @@ object StdNames { val unbox: N = "unbox" val universe: N = "universe" val unsafeNulls: N = "unsafeNulls" + val safeNulls: N = "safeNulls" val update: N = "update" val updateDynamic: N = "updateDynamic" val uses: N = "uses" diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 2b0585260a2b..af0ad5b1c7ce 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -423,7 +423,10 @@ class TreeUnpickler(reader: TastyReader, if nothingButMods(end) then AliasingBounds(readVariances(lo)) else val hi = readVariances(readType()) - createNullableTypeBounds(lo, hi) + if (ctx.flexifyTasty && !explicitNulls) + createNullableTypeBounds(lo, hi) + else + TypeBounds(lo, hi) case ANNOTATEDtype => val parent = readType() val ann = @@ -1694,7 +1697,10 @@ class TreeUnpickler(reader: TastyReader, val lo = readTpt() val hi = if currentAddr == end then lo else readTpt() val alias = if currentAddr == end then EmptyTree else readTpt() - createNullableTypeBoundsTree(lo, hi, alias) + if (ctx.flexifyTasty && !explicitNulls) + createNullableTypeBoundsTree(lo, hi, alias) + else + TypeBoundsTree(lo, hi, alias) case QUOTE => Quote(readTree(), Nil).withBodyType(readType()) case SPLICE => diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index da811dd2de1d..bae41ef01674 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -336,7 +336,10 @@ class PlainPrinter(_ctx: Context) extends Printer { case _ => toTextLocal(tpe) ~ " " ~ toText(annot) case FlexibleType(_, tpe) => - "(" ~ toText(tpe) ~ ")?" + if (ctx.settings.YhideFlexibleTypes.value) then + toText(tpe) + else + "(" ~ toText(tpe) ~ ")?" case tp: TypeVar => def toTextCaret(tp: Type) = if printDebug then toTextLocal(tp) ~ Str("^") else toText(tp) if (tp.isInstantiated) diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index 3045aa2b0fe3..357b554ea8c1 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -292,7 +292,7 @@ class Pickler extends Phase { val attributes = Attributes( sourceFile = sourceRelativePath, scala2StandardLibrary = Feature.shouldBehaveAsScala2, - explicitNulls = ctx.settings.YexplicitNulls.value, + explicitNulls = ctx.explicitNulls, captureChecked = Feature.ccEnabled, withPureFuns = Feature.pureFunsEnabled, isJava = isJavaAttr, diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 00da036dae53..3070de6c7aed 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -982,9 +982,9 @@ trait Applications extends Compatibility { // However, for overload resolution, we want to check applicability: // "could this work with some type instantiation?" (yes, if ? = String) def wildcardArgOK = - argtpe match + argtpe.stripNull() match case at @ AppliedType(tycon1, args1) if at.hasWildcardArg => - formal match + formal.stripNull() match case AppliedType(tycon2, args2) if tycon1 =:= tycon2 && args1.length == args2.length => // We need to handle all 4 cases, in addition to diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 4e2a68db6798..8b22f9da2970 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -238,7 +238,7 @@ class CompilationTests { val compilationTest = withCoverage(aggregateTests( compileFilesInDir("tests/explicit-nulls/pos", explicitNullsOptions), compileFilesInDir("tests/explicit-nulls/flexible-types-common", explicitNullsOptions), - compileFilesInDir("tests/explicit-nulls/unsafe-common", explicitNullsOptions `and` "-language:unsafeNulls" `and` "-Yno-flexible-types"), + compileFilesInDir("tests/explicit-nulls/unsafe-common", defaultOptions `and` "-Yno-flexible-types"), )) runWithCoverageOrFallback[PosTestWithCoverage](compilationTest, "Pos") diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 9049e6736c41..a80a079a7be3 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -62,7 +62,7 @@ object TestConfiguration { Properties.sourcecode )) - lazy val replWithStagingClasspath = + lazy val replWithStagingClasspath = replClassPath + File.pathSeparator + mkClasspath(List(Properties.dottyStaging)) def mkClasspath(classpaths: List[String]): String = @@ -101,7 +101,7 @@ object TestConfiguration { val picklingWithCompilerOptions = picklingOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath) - val explicitNullsOptions = defaultOptions `and` "-Yexplicit-nulls" + val explicitNullsOptions = defaultOptions `and` "-language:safeNulls" /** Default target of the generated class files */ private def defaultTarget: String = "17" diff --git a/docs/_docs/reference/error-codes/E008.md b/docs/_docs/reference/error-codes/E008.md index a6630170f6ea..b0309591bb40 100644 --- a/docs/_docs/reference/error-codes/E008.md +++ b/docs/_docs/reference/error-codes/E008.md @@ -16,23 +16,23 @@ This commonly occurs when: ## Example ```scala sc:fail sc-opts:-explain -val result = "hello".unknownMethod +val result: String = "hello".unknownMethod ``` ### Error ```scala sc:nocompile --- [E008] Not Found Error: example.scala:1:21 ---------------------------------- -1 |val result = "hello".unknownMethod - | ^^^^^^^^^^^^^^^^^^^^^ - | value unknownMethod is not a member of String +-- [E008] Not Found Error: example.scala:1:29 ---------------------------------- +1 |val result: String = "hello".unknownMethod + | ^^^^^^^^^^^^^^^^^^^^^ + | value unknownMethod is not a member of String ``` ### Solution ```scala sc:compile // Use a method that exists on the type -val result = "hello".toUpperCase +val result: String = "hello".toUpperCase ``` ```scala sc:compile diff --git a/docs/_docs/reference/error-codes/E208.md b/docs/_docs/reference/error-codes/E208.md index f928d309b210..cd4804b8d0d4 100644 --- a/docs/_docs/reference/error-codes/E208.md +++ b/docs/_docs/reference/error-codes/E208.md @@ -12,14 +12,14 @@ Extension methods are typically invoked as `receiver.method()`, where the receiv ## Example ```scala sc:fail sc-opts:-Werror -extension (s: String = "hello, world") def invert = s.reverse.toUpperCase +extension (s: String = "hello, world") def invert: String = s.reverse.toUpperCase ``` ### Error ```scala sc:nocompile -- [E208] Potential Issue Warning: example.scala:1:23 -------------------------- -1 |extension (s: String = "hello, world") def invert = s.reverse.toUpperCase +1 |extension (s: String = "hello, world") def invert: String = s.reverse.toUpperCase | ^ |Extension method invert should not have a default argument for its receiver. |----------------------------------------------------------------------------- @@ -44,7 +44,7 @@ it should not be defined as an extension. Remove the default argument from the receiver parameter: ```scala sc:compile sc-opts:-Werror -extension (s: String) def invert = s.reverse.toUpperCase +extension (s: String) def invert: String = s.reverse.toUpperCase ``` If you need a function with a default argument, define it as a regular method instead of an extension: diff --git a/language-server/test/dotty/tools/languageserver/CompletionTest.scala b/language-server/test/dotty/tools/languageserver/CompletionTest.scala index e06e6c78f5bb..1d0dc8345e32 100644 --- a/language-server/test/dotty/tools/languageserver/CompletionTest.scala +++ b/language-server/test/dotty/tools/languageserver/CompletionTest.scala @@ -197,12 +197,12 @@ class CompletionTest { @Test def importJavaStaticMethod: Unit = { code"""import java.lang.System.lineSep${m1}""" - .completion(("lineSeparator", Method, "(): String")) + .completion(("lineSeparator", Method, "(): (String)?")) } @Test def importJavaStaticField: Unit = { code"""import java.lang.System.ou${m1}""" - .completion(("out", Field, "java.io.PrintStream")) + .completion(("out", Field, "(java.io.PrintStream)?")) } @Test def importFromExplicitAndSyntheticPackageObject: Unit = { diff --git a/library/src/scala/language.scala b/library/src/scala/language.scala index 04ec3d603d14..c1c0f7dc2221 100644 --- a/library/src/scala/language.scala +++ b/library/src/scala/language.scala @@ -446,6 +446,9 @@ object language { @compileTimeOnly("`unsafeNulls` can only be used at compile time in import statements") object unsafeNulls + @compileTimeOnly("`safeNulls` can only be used at compile time in import statements") + object safeNulls + @compileTimeOnly("`future` can only be used at compile time in import statements") object future diff --git a/presentation-compiler/src/main/dotty/tools/pc/InferredMethodProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/InferredMethodProvider.scala index 705220b067b2..c7c457ed71d9 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/InferredMethodProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/InferredMethodProvider.scala @@ -68,7 +68,11 @@ final class InferredMethodProvider( Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx) given locatedCtx: Context = driver.localContext(params) - val indexedCtx = IndexedContext(pos)(using locatedCtx) + val locatedCtx2 = locatedCtx.fresh.setSettings(ctx.settings.YhideFlexibleTypes.updateIn( + ctx.settingsState.reinitializedCopy(), + true + )) + val indexedCtx = IndexedContext(pos)(using locatedCtx2) val autoImportsGen = AutoImports.generator( pos, diff --git a/presentation-compiler/src/main/dotty/tools/pc/InferredTypeProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/InferredTypeProvider.scala index e60d21339415..c477646a741c 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/InferredTypeProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/InferredTypeProvider.scala @@ -75,7 +75,11 @@ final class InferredTypeProvider( Interactive.pathTo(driver.openedTrees(uri), pos)(using driver.currentCtx) given locatedCtx: Context = driver.localContext(params) - val indexedCtx = IndexedContext(pos)(using locatedCtx) + val locatedCtx2 = locatedCtx.fresh.setSettings(ctx.settings.YhideFlexibleTypes.updateIn( + ctx.settingsState.reinitializedCopy(), + true + )) + val indexedCtx = IndexedContext(pos)(using locatedCtx2) val autoImportsGen = AutoImports.generator( pos, sourceText, diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala index 4b07417cf37e..f43dd5571296 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala @@ -82,6 +82,7 @@ class CompletionProvider( case Some(unit) => val newctx = ctx.fresh .setCompilationUnit(unit) + .setSettings(ctx.settings.YhideFlexibleTypes.updateIn(ctx.settingsState.reinitializedCopy(), true)) .setProfiler(Profiler()(using ctx)) .withPhase(Phases.typerPhase(using ctx)) val tpdPath0 = Interactive.pathTo(unit.tpdTree, pos.span)(using newctx) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDocSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDocSuite.scala index d125e8a651b4..469e6590dde8 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDocSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverDocSuite.scala @@ -26,11 +26,11 @@ class HoverDocSuite extends BaseHoverSuite: |""".stripMargin, """|**Expression type**: |```scala - |java.util.List[Int] + |(java.util.List[Int])? |``` |**Symbol signature**: |```scala - |final def emptyList[T](): java.util.List[T] + |final def emptyList[T](): (java.util.List[T])? |``` |Found documentation for java/util/Collections#emptyList(). |""".stripMargin @@ -57,7 +57,7 @@ class HoverDocSuite extends BaseHoverSuite: |} """.stripMargin, """|```scala - |def substring(beginIndex: Int): String + |def substring(beginIndex: Int): (String)? |``` |Found documentation for java/lang/String#substring(). |""".stripMargin diff --git a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala index ba9ba9c744ad..cf7b19d460ff 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/hover/HoverTermSuite.scala @@ -818,7 +818,7 @@ class HoverTermSuite extends BaseHoverSuite: """|package tests.macros |def m = Macros7460.foo.sub@@string(2, 4) |""".stripMargin, - "def substring(x$0: Int, x$1: Int): String".hover + "def substring(x$0: Int, x$1: Int): (String)?".hover ) @Test def `i7460-2` = @@ -826,7 +826,7 @@ class HoverTermSuite extends BaseHoverSuite: """|package tests.macros |def m = Macros7460.bar.sub@@string(2, 4) |""".stripMargin, - "def substring(x$0: Int, x$1: Int): String".hover + "def substring(x$0: Int, x$1: Int): (String)?".hover ) @Test def `multiple-valdefs-1` = diff --git a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala index 9fd15c86d2a3..f7b2c601f47f 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala @@ -1270,8 +1270,8 @@ class InlayHintsSuite extends BaseInlayHintsSuite { |""".stripMargin, """|object Main { | val str/*: String<>*/ = "hello" - | val sub/*: String<>*/ = str.substring(1, 3) - | val replaced/*: String<>*/ = str.replace('l', 'x') + | val sub/*: (String<>)?*/ = str.substring(1, 3) + | val replaced/*: (String<>)?*/ = str.replace('l', 'x') |} |""".stripMargin ) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpDocSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpDocSuite.scala index 4082c4204909..c1e9c3cfc54d 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpDocSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpDocSuite.scala @@ -161,8 +161,8 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite: |} """.stripMargin, """|Found documentation for java/util/Collections#singleton(). - |singleton[T](o: T): java.util.Set[T] - | ^^^^ + |singleton[T](o: (T)?): (java.util.Set[T])? + | ^^^^^^^ | @param T Found documentation for type param T | @param o Found documentation for param o |""".stripMargin @@ -191,11 +191,11 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite: | new java.io.File(@@) |} """.stripMargin, - """|File(uri: URI) - | ^^^^^^^^ - |File(parent: File, child: String) - |File(parent: String, child: String) - |File(pathname: String) + """|File(uri: (URI)?) + | ^^^^^^^^^^^ + |File(parent: (File)?, child: (String)?) + |File(parent: (String)?, child: (String)?) + |File(pathname: (String)?) |""".stripMargin ) @@ -206,8 +206,8 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite: | "".substring(1@@) |} """.stripMargin, - """|substring(beginIndex: Int, endIndex: Int): String - |substring(beginIndex: Int): String + """|substring(beginIndex: Int, endIndex: Int): (String)? + |substring(beginIndex: Int): (String)? | ^^^^^^^^^^^^^^^ |""".stripMargin ) @@ -219,16 +219,16 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite: | String.valueOf(1@@) |} """.stripMargin, - """|valueOf(d: Double): String - |valueOf(f: Float): String - |valueOf(l: Long): String - |valueOf(i: Int): String + """|valueOf(d: Double): (String)? + |valueOf(f: Float): (String)? + |valueOf(l: Long): (String)? + |valueOf(i: Int): (String)? | ^^^^^^ - |valueOf(c: Char): String - |valueOf(b: Boolean): String - |valueOf(data: Array[Char], offset: Int, count: Int): String - |valueOf(data: Array[Char]): String - |valueOf(obj: Object): String + |valueOf(c: Char): (String)? + |valueOf(b: Boolean): (String)? + |valueOf(data: (Array[Char])?, offset: Int, count: Int): (String)? + |valueOf(data: (Array[Char])?): (String)? + |valueOf(obj: (Object)?): (String)? |""".stripMargin ) @@ -239,16 +239,16 @@ class SignatureHelpDocSuite extends BaseSignatureHelpSuite: | String.valueOf(@@) |} """.stripMargin, - """|valueOf(d: Double): String + """|valueOf(d: Double): (String)? | ^^^^^^^^^ - |valueOf(f: Float): String - |valueOf(l: Long): String - |valueOf(i: Int): String - |valueOf(c: Char): String - |valueOf(b: Boolean): String - |valueOf(data: Array[Char], offset: Int, count: Int): String - |valueOf(data: Array[Char]): String - |valueOf(obj: Object): String + |valueOf(f: Float): (String)? + |valueOf(l: Long): (String)? + |valueOf(i: Int): (String)? + |valueOf(c: Char): (String)? + |valueOf(b: Boolean): (String)? + |valueOf(data: (Array[Char])?, offset: Int, count: Int): (String)? + |valueOf(data: (Array[Char])?): (String)? + |valueOf(obj: (Object)?): (String)? |""".stripMargin ) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala index 2222cf496220..313a2d5bcc16 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/signaturehelp/SignatureHelpSuite.scala @@ -77,9 +77,9 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite: | new ProcessBuilder(@@) |} """.stripMargin, - """|ProcessBuilder(x$0: String*) - | ^^^^^^^^^^^^ - |ProcessBuilder(x$0: java.util.List[String]) + """|ProcessBuilder(x$0: ((String)?*)?) + | ^^^^^^^^^^^^^^^^^^ + |ProcessBuilder(x$0: (java.util.List[String])?) |""".stripMargin ) @@ -103,11 +103,11 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite: | new File(@@) |} """.stripMargin, - """|File(x$0: URI) - | ^^^^^^^^ - |File(x$0: File, x$1: String) - |File(x$0: String, x$1: String) - |File(x$0: String) + """|File(x$0: (URI)?) + | ^^^^^^^^^^^ + |File(x$0: (File)?, x$1: (String)?) + |File(x$0: (String)?, x$1: (String)?) + |File(x$0: (String)?) |""".stripMargin ) @@ -118,11 +118,11 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite: | new java.io.File(@@) |} """.stripMargin, - """|File(x$0: URI) - | ^^^^^^^^ - |File(x$0: File, x$1: String) - |File(x$0: String, x$1: String) - |File(x$0: String) + """|File(x$0: (URI)?) + | ^^^^^^^^^^^ + |File(x$0: (File)?, x$1: (String)?) + |File(x$0: (String)?, x$1: (String)?) + |File(x$0: (String)?) |""".stripMargin ) @@ -554,8 +554,8 @@ class SignatureHelpSuite extends BaseSignatureHelpSuite: |} """.stripMargin, // This is the correct result, as there is a conflict at Function: scala.Function and java.util.function.Function - """|computeIfAbsent(x$0: String, x$1: java.util.function.Function[? >: String, ? <: Int]): Int - | ^^^^^^^^^^^ + """|computeIfAbsent(x$0: (String)?, x$1: (java.util.function.Function[? >: String, ? <: Int])?): (Int)? + | ^^^^^^^^^^^^^^ |""".stripMargin ) diff --git a/project/MiMaFilters.scala b/project/MiMaFilters.scala index 6a8a9326b6d0..7dd43c63c3c9 100644 --- a/project/MiMaFilters.scala +++ b/project/MiMaFilters.scala @@ -15,7 +15,9 @@ object MiMaFilters { ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.ArrayOps.iterateUntilEmpty$extension"), ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.ArrayOps.scala$collection$ArrayOps$$elemTag$extension"), ProblemFilters.exclude[MissingFieldProblem]("scala.language#experimental.safe"), - ProblemFilters.exclude[MissingClassProblem]("scala.language$experimental$safe$") + ProblemFilters.exclude[MissingClassProblem]("scala.language$experimental$safe$"), + ProblemFilters.exclude[MissingFieldProblem]("scala.language.safeNulls"), + ProblemFilters.exclude[MissingClassProblem]("scala.language$safeNulls$"), )) val BackwardsBreakingChanges: Map[String, Seq[ProblemFilter]] = Map( diff --git a/repl/test/dotty/tools/repl/TabcompleteTests.scala b/repl/test/dotty/tools/repl/TabcompleteTests.scala index 0541e25b2992..f098d6b21722 100644 --- a/repl/test/dotty/tools/repl/TabcompleteTests.scala +++ b/repl/test/dotty/tools/repl/TabcompleteTests.scala @@ -104,8 +104,7 @@ class TabcompleteTests extends ReplTest { @Test def `null` = initially { val comp = tabComplete("null.") assertEquals( - List("!=", "##", "==", "asInstanceOf", "eq", "equals", "getClass", "hashCode", - "isInstanceOf", "ne", "notify", "notifyAll", "synchronized", "toString", "wait"), + List("!=", "##", "==", "asInstanceOf", "equals", "getClass", "hashCode", "isInstanceOf", "toString"), comp.distinct.sorted) } @@ -244,6 +243,6 @@ class TabcompleteTests extends ReplTest { } @Test def i9334 = initially { - assert(tabComplete("class Foo[T]; classOf[Foo].").contains("getName")) + assertEquals(Nil, tabComplete("class Foo[T]; classOf[Foo].")) } } diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/JavadocAnchorCreator.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/JavadocAnchorCreator.scala index ea7dc32a7e58..aeddca9792d5 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/JavadocAnchorCreator.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/JavadocAnchorCreator.scala @@ -28,6 +28,7 @@ object JavadocAnchorCreator: private def transformType(using Quotes)(tpe: reflect.TypeRepr): String = import reflect.* tpe.simplified match + case FlexibleType(hi) => transformType(hi) case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.ArrayClass) => transformType(typeList.head) + ":A" case AppliedType(tpe, typeList) if tpe.classSymbol.fold(false)(_ == defn.RepeatedParamClass) => transformType(typeList.head) + "..." case AppliedType(tpe, typeList) => transformPrimitiveType(tpe) diff --git a/tests/explicit-nulls/pos/i23936.scala b/tests/explicit-nulls/pos/i23936.scala index 041e358c87f0..cd1c65a4caa2 100644 --- a/tests/explicit-nulls/pos/i23936.scala +++ b/tests/explicit-nulls/pos/i23936.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls +//> using options -language:safeNulls sealed abstract class IsSubtypeOfOutput[-A, +B] extends (A => B) object IsSubtypeOfOutput: diff --git a/tests/explicit-nulls/pos/i24440.scala b/tests/explicit-nulls/pos/i24440.scala index 0ef3e88e7cf7..ab3143031bcc 100644 --- a/tests/explicit-nulls/pos/i24440.scala +++ b/tests/explicit-nulls/pos/i24440.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Werror +//> using options -language:safeNulls -Werror trait AwtComponentLogging extends java.awt.Component: diff --git a/tests/init/pos/Properties.scala b/tests/init/pos/Properties.scala index 8dd2fa052c0b..1278f41e992f 100644 --- a/tests/init/pos/Properties.scala +++ b/tests/init/pos/Properties.scala @@ -39,18 +39,18 @@ private[scala] trait PropertiesTrait { final def propIsSet(name: String) = System.getProperty(name) != null final def propIsSetTo(name: String, value: String) = propOrNull(name) == value - final def propOrElse(name: String, alt: String) = System.getProperty(name, alt) - final def propOrEmpty(name: String) = propOrElse(name, "") - final def propOrNull(name: String) = propOrElse(name, null) - final def propOrNone(name: String) = Option(propOrNull(name)) + final def propOrElse(name: String, alt: String): String = System.getProperty(name, alt) + final def propOrEmpty(name: String): String = propOrElse(name, "") + final def propOrNull(name: String): String | Null = propOrElse(name, null) + final def propOrNone(name: String): Option[String] = Option(propOrNull(name)) final def propOrFalse(name: String) = propOrNone(name) exists (x => List("yes", "on", "true") contains x.toLowerCase) - final def setProp(name: String, value: String) = System.setProperty(name, value) - final def clearProp(name: String) = System.clearProperty(name) + final def setProp(name: String, value: String): String = System.setProperty(name, value) + final def clearProp(name: String): String = System.clearProperty(name) - final def envOrElse(name: String, alt: String) = Option(System.getenv(name)) getOrElse alt - final def envOrNone(name: String) = Option(System.getenv(name)) + final def envOrElse(name: String, alt: String): String = Option(System.getenv(name)) getOrElse alt + final def envOrNone(name: String): Option[String] = Option(System.getenv(name)) - final def envOrSome(name: String, alt: Option[String]) = envOrNone(name) orElse alt + final def envOrSome(name: String, alt: Option[String]): Option[String] = envOrNone(name) orElse alt // for values based on propFilename, falling back to System properties final def scalaPropOrElse(name: String, alt: String): String = scalaPropOrNone(name).getOrElse(alt) diff --git a/tests/init/warn/java1.scala b/tests/init/warn/java1.scala index 36044413d2ea..d09f3ef0fa78 100644 --- a/tests/init/warn/java1.scala +++ b/tests/init/warn/java1.scala @@ -4,7 +4,7 @@ import java.util.function.Consumer class A extends Spliterator.OfDouble: def characteristics() = 10 def estimateSize() = 10 - def trySplit() = ??? + def trySplit(): Spliterator.OfDouble = ??? def tryAdvance(x$0: java.util.function.DoubleConsumer): Boolean = false val m = n + 1 diff --git a/tests/neg-deep-subtype/interop-polytypes.scala b/tests/neg-deep-subtype/interop-polytypes.scala index 987e4720bf13..defe31322a15 100644 --- a/tests/neg-deep-subtype/interop-polytypes.scala +++ b/tests/neg-deep-subtype/interop-polytypes.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Yno-flexible-types +//> using options -language:safeNulls -Yno-flexible-types class Foo { import java.util.ArrayList diff --git a/tests/neg/i16820.check b/tests/neg/i16820.check index 48824d683244..1d929a1ea8d2 100644 --- a/tests/neg/i16820.check +++ b/tests/neg/i16820.check @@ -17,7 +17,7 @@ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | missing argument list for method toRealPath in trait Path | - | def toRealPath(x$0: java.nio.file.LinkOption*): java.nio.file.Path + | def toRealPath(x$0: ((java.nio.file.LinkOption)?*)?): (java.nio.file.Path)? | | longer explanation available when compiling with `-explain` -- [E178] Type Error: tests/neg/i16820.scala:11:14 --------------------------------------------------------------------- diff --git a/tests/neg/i17467.check b/tests/neg/i17467.check index a274a519f69a..fdf6f1cdea06 100644 --- a/tests/neg/i17467.check +++ b/tests/neg/i17467.check @@ -1,5 +1,5 @@ --- [E007] Type Mismatch Error: tests/neg/i17467.scala:6:20 ------------------------------------------------------------- -6 | val b1: "foo" = null // error +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:8:20 ------------------------------------------------------------- +8 | val b1: "foo" = null // error | ^^^^ | Found: Null | Required: ("foo" : String) @@ -7,17 +7,17 @@ | must be more specific than ("foo" : String) | | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i17467.scala:9:22 ------------------------------------------------------------- -9 | val c2: c1.type = null // error - | ^^^^ - | Found: Null - | Required: (c1 : ("foo" : String)) - | Note that implicit conversions were not tried because the result of an implicit conversion - | must be more specific than (c1 : ("foo" : String)) - | - | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i17467.scala:17:22 ------------------------------------------------------------ -17 | val e2: e1.type = null // error +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:11:22 ------------------------------------------------------------ +11 | val c2: c1.type = null // error + | ^^^^ + | Found: Null + | Required: (c1 : ("foo" : String)) + | Note that implicit conversions were not tried because the result of an implicit conversion + | must be more specific than (c1 : ("foo" : String)) + | + | longer explanation available when compiling with `-explain` +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:19:22 ------------------------------------------------------------ +19 | val e2: e1.type = null // error | ^^^^ | Found: Null | Required: (e1 : MyNonNullable) @@ -25,12 +25,12 @@ | must be more specific than (e1 : MyNonNullable) | | longer explanation available when compiling with `-explain` --- [E172] Type Error: tests/neg/i17467.scala:19:26 --------------------------------------------------------------------- -19 | summon[Null <:< "foo"] // error +-- [E172] Type Error: tests/neg/i17467.scala:21:26 --------------------------------------------------------------------- +21 | summon[Null <:< "foo"] // error | ^ | Cannot prove that Null <:< ("foo" : String). --- [E007] Type Mismatch Error: tests/neg/i17467.scala:21:23 ------------------------------------------------------------ -21 | val f1: Mod.type = null // error +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:23:23 ------------------------------------------------------------ +23 | val f1: Mod.type = null // error | ^^^^ | Found: Null | Required: Test.Mod.type @@ -38,14 +38,14 @@ | must be more specific than Test.Mod.type | | longer explanation available when compiling with `-explain` --- [E083] Type Error: tests/neg/i17467.scala:24:12 --------------------------------------------------------------------- -24 | val g2: g1.type = null // error // error +-- [E083] Type Error: tests/neg/i17467.scala:26:12 --------------------------------------------------------------------- +26 | val g2: g1.type = null // error // error | ^^^^^^^ | (g1 : AnyRef) is not a valid singleton type, since it is not an immutable path | | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i17467.scala:24:22 ------------------------------------------------------------ -24 | val g2: g1.type = null // error // error +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:26:22 ------------------------------------------------------------ +26 | val g2: g1.type = null // error // error | ^^^^ | Found: Null | Required: (g1 : AnyRef) @@ -53,8 +53,8 @@ | must be more specific than (g1 : AnyRef) | | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i17467.scala:36:24 ------------------------------------------------------------ -36 | def me: this.type = null // error +-- [E007] Type Mismatch Error: tests/neg/i17467.scala:38:24 ------------------------------------------------------------ +38 | def me: this.type = null // error | ^^^^ | Found: Null | Required: (Baz.this : Test.Baz) diff --git a/tests/neg/i17467.scala b/tests/neg/i17467.scala index f8023e74742f..9999a19ef015 100644 --- a/tests/neg/i17467.scala +++ b/tests/neg/i17467.scala @@ -1,3 +1,5 @@ +//> using options -Yno-explicit-nulls + object Test: def test(): Unit = val a1: String = "foo" diff --git a/tests/neg/i1793.scala b/tests/neg/i1793.scala index ea6d3bcb78c6..0451b634228b 100644 --- a/tests/neg/i1793.scala +++ b/tests/neg/i1793.scala @@ -1,3 +1,5 @@ +//> using options -Yno-explicit-nulls + object Test { import scala.ref.WeakReference def unapply[T <: AnyVal](wr: WeakReference[T]): Option[T] = { diff --git a/tests/neg/i2033.check b/tests/neg/i2033.check index 7737bba96a5e..85fa235b0c3c 100644 --- a/tests/neg/i2033.check +++ b/tests/neg/i2033.check @@ -1,7 +1,7 @@ -- Error: tests/neg/i2033.scala:7:30 ----------------------------------------------------------------------------------- 7 | val arr = bos toByteArray () // error | ^^ - |can't supply unit value with infix notation because nullary method toByteArray in class ByteArrayOutputStream: (): Array[Byte] takes no arguments; use dotted invocation instead: (...).toByteArray() + |can't supply unit value with infix notation because nullary method toByteArray in class ByteArrayOutputStream: (): (Array[Byte])? takes no arguments; use dotted invocation instead: (...).toByteArray() -- [E007] Type Mismatch Error: tests/neg/i2033.scala:20:35 ------------------------------------------------------------- 20 | val out = new ObjectOutputStream(println) // error | ^^^^^^^ diff --git a/tests/neg/i24711-java-nested-types.check b/tests/neg/i24711-java-nested-types.check index 005a0ab71e52..6e22fa2800e6 100644 --- a/tests/neg/i24711-java-nested-types.check +++ b/tests/neg/i24711-java-nested-types.check @@ -5,7 +5,7 @@ | Required: Int | | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i24711-java-nested-types.scala:4:38 ------------------------------------------- +-- [E007] Type Mismatch Error: tests/neg/i24711-java-nested-types.scala:4:19 ------------------------------------------- 4 | val test2: Int = java.util.Map.entry("key", 1) // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | Found: java.util.Map.Entry[String, Int] diff --git a/tests/pos/i19806/J.tastycheck b/tests/pos/i19806/J.tastycheck index 110c33310e43..e7f94b8594da 100644 --- a/tests/pos/i19806/J.tastycheck +++ b/tests/pos/i19806/J.tastycheck @@ -153,7 +153,8 @@ Positions (145 bytes, starting from ): source paths: 0: 23 [] -Attributes (4 bytes, starting from ): +Attributes (5 bytes, starting from ): + EXPLICITNULLSattr JAVAattr OUTLINEattr SOURCEFILEattr 23 [] diff --git a/tests/pos/i20901/Foo.tastycheck b/tests/pos/i20901/Foo.tastycheck index 82e95946f96c..e0c7f0de73a6 100644 --- a/tests/pos/i20901/Foo.tastycheck +++ b/tests/pos/i20901/Foo.tastycheck @@ -122,5 +122,6 @@ Positions (75 bytes, starting from ): source paths: 0: 32 [] -Attributes (2 bytes, starting from ): +Attributes (3 bytes, starting from ): + EXPLICITNULLSattr SOURCEFILEattr 32 [] diff --git a/tests/pos/i21154/Z.tastycheck b/tests/pos/i21154/Z.tastycheck index 8ba6e2a43a4d..23298e88b6bc 100644 --- a/tests/pos/i21154/Z.tastycheck +++ b/tests/pos/i21154/Z.tastycheck @@ -251,5 +251,6 @@ Positions (154 bytes, starting from ): source paths: 0: 19 [] -Attributes (2 bytes, starting from ): +Attributes (3 bytes, starting from ): + EXPLICITNULLSattr SOURCEFILEattr 19 [] diff --git a/tests/pos/inline-null-wrapper.scala b/tests/pos/inline-null-wrapper.scala index 3b53974ea4b9..72e50b36b15e 100644 --- a/tests/pos/inline-null-wrapper.scala +++ b/tests/pos/inline-null-wrapper.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls +//> using options -language:safeNulls import annotation.targetName class A diff --git a/tests/run-macros/annot-arg-value-in-java.check b/tests/run-macros/annot-arg-value-in-java.check index 74821d24bf26..46cf4aa998bc 100644 --- a/tests/run-macros/annot-arg-value-in-java.check +++ b/tests/run-macros/annot-arg-value-in-java.check @@ -1,7 +1,7 @@ J: new java.lang.SuppressWarnings(value = "a") new java.lang.SuppressWarnings(value = "b") -new java.lang.SuppressWarnings(value = _root_.scala.Array.apply[java.lang.String]("c", "d")(scala.reflect.ClassTag.apply[java.lang.String](classOf[java.lang.String]))) +new java.lang.SuppressWarnings(value = _root_.scala.Array.apply[(java.lang.String)?]("c", "d")(scala.reflect.ClassTag.apply[(java.lang.String)?](classOf[java.lang.String]))) JOtherTypes: new Annot(value = 1, m = _, n = _) new Annot(value = -2, m = _, n = _) diff --git a/tests/run-macros/i20052.check b/tests/run-macros/i20052.check index ca45222cf4cf..99dfa26b8522 100644 --- a/tests/run-macros/i20052.check +++ b/tests/run-macros/i20052.check @@ -2,4 +2,4 @@ method (Flags.JavaDefined | Flags.Method) List(List((x$0,scala.Int))) method (Flags.JavaDefined | Flags.Method) List(List()) method (Flags.JavaDefined | Flags.Method | Flags.Private) List(List()) method (Flags.JavaDefined | Flags.Method | Flags.Private) List(List()) -method (Flags.JavaDefined | Flags.Method) List(List((A,_ >: scala.Nothing <: .)), List((x$0,A))) +method (Flags.JavaDefined | Flags.Method) List(List((A,_ >: scala.Nothing <: .)), List((x$0,(A)?))) diff --git a/tests/semanticdb/expect/semanticdb-Types.expect.scala b/tests/semanticdb/expect/semanticdb-Types.expect.scala index a44252846153..592fbddfc4ab 100644 --- a/tests/semanticdb/expect/semanticdb-Types.expect.scala +++ b/tests/semanticdb/expect/semanticdb-Types.expect.scala @@ -70,8 +70,8 @@ object Test/*<-types::Test.*/ { val annType2/*<-types::Test.C#annType2.*/: T/*->types::T#*/ @ann1/*->types::ann1#*/ @ann2/*->types::ann2#*/ = ???/*->scala::Predef.`???`().*/ val existentialType2/*<-types::Test.C#existentialType2.*/: List/*->scala::package.List#*/[_] = ???/*->scala::Predef.`???`().*/ - val existentialType3/*<-types::Test.C#existentialType3.*/ = Class/*->java::lang::Class#*/.forName/*->java::lang::Class#forName().*/("foo.Bar") - val existentialType4/*<-types::Test.C#existentialType4.*/ = Class/*->java::lang::Class#*/.forName/*->java::lang::Class#forName().*/("foo.Bar") + val existentialType3/*<-types::Test.C#existentialType3.*/: Class/*->scala::Predef.Class#*/[?] = Class/*->java::lang::Class#*/.forName/*->java::lang::Class#forName().*/("foo.Bar") + val existentialType4/*<-types::Test.C#existentialType4.*/: Class/*->scala::Predef.Class#*/[?] = Class/*->java::lang::Class#*/.forName/*->java::lang::Class#forName().*/("foo.Bar") def typeLambda1/*<-types::Test.C#typeLambda1().*/[M/*<-types::Test.C#typeLambda1().[M]*/[_]] = ???/*->scala::Predef.`???`().*/ typeLambda1/*->types::Test.C#typeLambda1().*/[({ type L/*<-local11*/[T/*<-local10*/] = List/*->scala::package.List#*/[T/*->local10*/] })#L] diff --git a/tests/semanticdb/expect/semanticdb-Types.scala b/tests/semanticdb/expect/semanticdb-Types.scala index 0ce6bdc625e1..e3e0e4d343f6 100644 --- a/tests/semanticdb/expect/semanticdb-Types.scala +++ b/tests/semanticdb/expect/semanticdb-Types.scala @@ -70,8 +70,8 @@ object Test { val annType2: T @ann1 @ann2 = ??? val existentialType2: List[_] = ??? - val existentialType3 = Class.forName("foo.Bar") - val existentialType4 = Class.forName("foo.Bar") + val existentialType3: Class[?] = Class.forName("foo.Bar") + val existentialType4: Class[?] = Class.forName("foo.Bar") def typeLambda1[M[_]] = ??? typeLambda1[({ type L[T] = List[T] })#L] diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 971ff1d9f329..4c42d05e5df9 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -5589,7 +5589,7 @@ Uri => semanticdb-Types.scala Text => empty Language => Scala Symbols => 143 entries -Occurrences => 246 entries +Occurrences => 248 entries Diagnostics => 4 entries Synthetics => 1 entries @@ -5889,11 +5889,13 @@ Occurrences: [71:26..71:30): List -> scala/package.List# [71:36..71:39): ??? -> scala/Predef.`???`(). [72:8..72:24): existentialType3 <- types/Test.C#existentialType3. -[72:27..72:32): Class -> java/lang/Class# -[72:33..72:40): forName -> java/lang/Class#forName(). +[72:26..72:31): Class -> scala/Predef.Class# +[72:37..72:42): Class -> java/lang/Class# +[72:43..72:50): forName -> java/lang/Class#forName(). [73:8..73:24): existentialType4 <- types/Test.C#existentialType4. -[73:27..73:32): Class -> java/lang/Class# -[73:33..73:40): forName -> java/lang/Class#forName(). +[73:26..73:31): Class -> scala/Predef.Class# +[73:37..73:42): Class -> java/lang/Class# +[73:43..73:50): forName -> java/lang/Class#forName(). [75:8..75:19): typeLambda1 <- types/Test.C#typeLambda1(). [75:20..75:21): M <- types/Test.C#typeLambda1().[M] [75:28..75:31): ??? -> scala/Predef.`???`(). diff --git a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala index 263a3b4774a3..801d74a12402 100644 --- a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala +++ b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/EnumTestScala3.scala @@ -126,7 +126,7 @@ class EnumTestScala3: end testCurrency2 @Test def testOpt(): Unit = - + import scala.language.safeNulls def encode[T <: AnyVal](t: Opt[T]): T | Null = t match case Opt.Sm(t) => t case Opt.Nn => null diff --git a/tests/warn/i12460.check b/tests/warn/i12460.check index ba44bed1a18f..23bf11276ed2 100644 --- a/tests/warn/i12460.check +++ b/tests/warn/i12460.check @@ -1,5 +1,5 @@ -- [E208] Potential Issue Warning: tests/warn/i12460.scala:3:23 -------------------------------------------------------- -3 |extension (s: String = "hello, world") def invert = s.reverse.toUpperCase // warn +3 |extension (s: String = "hello, world") def invert : String = s.reverse.toUpperCase // warn | ^ | Extension method invert should not have a default argument for its receiver. |--------------------------------------------------------------------------------------------------------------------- @@ -11,7 +11,7 @@ | it should not be defined as an extension. --------------------------------------------------------------------------------------------------------------------- -- [E208] Potential Issue Warning: tests/warn/i12460.scala:5:37 -------------------------------------------------------- -5 |extension (using String)(s: String = "hello, world") def revert = s.reverse.toUpperCase // warn +5 |extension (using String)(s: String = "hello, world") def revert : String = s.reverse.toUpperCase // warn | ^ | Extension method revert should not have a default argument for its receiver. |--------------------------------------------------------------------------------------------------------------------- diff --git a/tests/warn/i12460.scala b/tests/warn/i12460.scala index 0e37c6aa7de7..1aaff7a30ab2 100644 --- a/tests/warn/i12460.scala +++ b/tests/warn/i12460.scala @@ -1,9 +1,9 @@ //> using options -explain -Ystop-after:refchecks -extension (s: String = "hello, world") def invert = s.reverse.toUpperCase // warn +extension (s: String = "hello, world") def invert : String = s.reverse.toUpperCase // warn -extension (using String)(s: String = "hello, world") def revert = s.reverse.toUpperCase // warn +extension (using String)(s: String = "hello, world") def revert : String = s.reverse.toUpperCase // warn extension (s: String) - def divert(m: String = "hello, world") = (s+m).reverse.toUpperCase // ok - def divertimento(using String)(m: String = "hello, world") = (s+m).reverse.toUpperCase // ok + def divert(m: String = "hello, world") : String = (s+m).reverse.toUpperCase // ok + def divertimento(using String)(m: String = "hello, world") : String = (s+m).reverse.toUpperCase // ok diff --git a/tests/warn/i20132.future-Left.scala b/tests/warn/i20132.future-Left.scala index a25718eadb6b..f3d7584fe8f9 100644 --- a/tests/warn/i20132.future-Left.scala +++ b/tests/warn/i20132.future-Left.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Yno-flexible-types +//> using options -Yno-flexible-types import scala.language.unsafeNulls diff --git a/tests/warn/i20132.stream-Tuple2.safeNulls.fixed.scala b/tests/warn/i20132.stream-Tuple2.safeNulls.fixed.scala index 817d8ce06cee..21d316d695b9 100644 --- a/tests/warn/i20132.stream-Tuple2.safeNulls.fixed.scala +++ b/tests/warn/i20132.stream-Tuple2.safeNulls.fixed.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Yno-flexible-types +//> using options -language:safeNulls -Yno-flexible-types import scala.jdk.CollectionConverters.* diff --git a/tests/warn/i20132.stream-Tuple2.safeNulls.scala b/tests/warn/i20132.stream-Tuple2.safeNulls.scala index 2d4a2318039e..97d36da4cfd1 100644 --- a/tests/warn/i20132.stream-Tuple2.safeNulls.scala +++ b/tests/warn/i20132.stream-Tuple2.safeNulls.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Yno-flexible-types +//> using options -language:safeNulls -Yno-flexible-types import scala.jdk.CollectionConverters.* diff --git a/tests/warn/i20132.stream-Tuple2.scala b/tests/warn/i20132.stream-Tuple2.scala index b7cf58f8f930..e09edcbc5a73 100644 --- a/tests/warn/i20132.stream-Tuple2.scala +++ b/tests/warn/i20132.stream-Tuple2.scala @@ -1,4 +1,4 @@ -//> using options -Yexplicit-nulls -Yno-flexible-types +//> using options -Yno-flexible-types // Previously failed because the scrutinee under // unsafeNulls/explicit-nulls/no-flexible-types diff --git a/tests/warn/nonunit-statement.check b/tests/warn/nonunit-statement.check index 46a75dfd3065..751784e90f74 100644 --- a/tests/warn/nonunit-statement.check +++ b/tests/warn/nonunit-statement.check @@ -67,19 +67,19 @@ -- [E175] Potential Issue Warning: tests/warn/nonunit-statement.scala:126:37 ------------------------------------------- 126 | if (start.length != 0) jsb.append(start) // warn (value-discard) | ^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type StringBuilder. Add `: Unit` to discard silently. + | discarded non-Unit value of type (StringBuilder)?. Add `: Unit` to discard silently. -- [E175] Potential Issue Warning: tests/warn/nonunit-statement.scala:132:18 ------------------------------------------- 132 | jsb.append(it.next()) // warn (value-discard) | ^^^^^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type StringBuilder. Add `: Unit` to discard silently. + | discarded non-Unit value of type (StringBuilder)?. Add `: Unit` to discard silently. -- [E175] Potential Issue Warning: tests/warn/nonunit-statement.scala:135:35 ------------------------------------------- 135 | if (end.length != 0) jsb.append(end) // warn (value-discard) | ^^^^^^^^^^^^^^^ - | discarded non-Unit value of type StringBuilder. Add `: Unit` to discard silently. + | discarded non-Unit value of type (StringBuilder)?. Add `: Unit` to discard silently. -- [E175] Potential Issue Warning: tests/warn/nonunit-statement.scala:141:14 ------------------------------------------- 141 | b.append(it.next()) // warn (value-discard) | ^^^^^^^^^^^^^^^^^^^ - | discarded non-Unit value of type StringBuilder. Add `: Unit` to discard silently. + | discarded non-Unit value of type (StringBuilder)?. Add `: Unit` to discard silently. -- [E175] Potential Issue Warning: tests/warn/nonunit-statement.scala:146:30 ------------------------------------------- 146 | while (it.hasNext) it.next() // warn | ^^^^^^^^^