The fatal warnings PR (for library) was merged prematurely as it is
impacting my exhaustivity PR. Rather do anything (like rebase or tweak)
to the 12 commits that my PR consists of and therefore causing CI to
rebuild each commit, I'm separately going to PR disabling fatal
warnings, so I can merge my PR without it instantly breaking the 2.13.x
branch.
I'll do the same for the reflect and compiler PRs, and once we've
re-STARR'd we can re-enable fatal warnings by either resolving all the
exhaustivity warnings or opting out of them (or a mix of both).
The pattern matcher converts code like:
Box(Option("hello")) match {
case Box(Some(s)) =>
case Box(None) =>
}
into two invocations of Box.unapply, because it can't trust that
Box.unapply is idempotent. For case classes (like Some) it can, and
moreso it can just access the underlying values directly ("x1.value").
The exhaustivity/unreachability analysis builds on this (e.g
"pointsToBound.exists(sym => t.exists(_.symbol == sym)").
With the previous commits making the exhaustivity/unreachability checker
consider custom extractors this would result in multiple symbols for
each extraction (instead of all being "x1.value", for example) which
results in multiple SAT variables which results, basically, in warnings
that the value returned from the first extraction could None and the
second value could be Some - which is only true for a non-idempotent
Box.unapply. The intent of the previous commits (and the whole PR) is
to make the exhaustivity checker provide warnings that were previous
missing, but warning for fear of non-idempotent custom extractors would
produce more noise than signal.
Now, within a minor release like 2.13.4 we can't go and change the code
generation and thus the code semantics (Dotty can and apparently does),
but we can do the analysis with the assumption of idempotency. That's
what this does: in MatchApproximator's TreeMakersToProps use a cache for
the binders so when we see two extractions that are equivalent we reuse
the same binder, so it translates into the same SAT variable.
After the previous commit, the field for a `private[this] var` class
parameter is only elided if the field is not used at all. This seems
not to be worth the effort.
Reads of `var` class parameters in the constructor are not rewritten to
the constructor parameter, they keep referring to the field to ensure
potential field writes are reflected (this was fixed in #7688).
This means that the corresponding field cannot be elided even if it's
never written.
The alternative solution would be to detect `private[this] var` fields
that are only read in the constructor. However this is difficult to
implement, see #9143.
- Special case result sizes of 0-4 and avoid mutable.HashMap
allocation.
- Expose entriesIterator through a private[collection] method,
rather than via subclassing, to avoid changing the JIT
of code using mutable.HashMap that might currently rely on
Class Heirarchy Analysis noticing that it effectively final.
- Fuse some lambdas into `object grouper`.
Fix appending a `ListBuffer` to itself and subtracting
a `ListBuffer` from itself.
Fix appending a `Growable` that uses the default
`addAll` implementation to itself.
Like Scala, an import in Java can shadow a definition
in another file, if it is not import-on-demand.
The implementation bailed too quickly from searching
enclosing contexts while testing this condition.
Remove withDefault.
OutputSetting is StringSetting loosely coupled
to outputDirs.
MultiStringSetting takes a default
Back out clearSetByUser, which worked around initialization
of the setting.
(cherry picked from commit 649fea5d13)
Previously, a bad compiler option was ignored.
Add a common idiom to StreamCapture to set stdout;
the idiom may be suboptimal for testing.
Convert a partest to junit for regex, and eliminate
one check file.
(cherry picked from commit 580ed0706d)
If there is an error running a forked command, such as
a Test or javac, log it instead of letting sbt swallow
the exception. (It offers to let you run the last command
to see the stack trace.)
This helps if javac goes missing.
(cherry picked from commit f34229300d)
Previously, hasWarning meant a warning had been displayed
(as opposed to counted). Since last refactor, it means
counted, so warnings were summarized under -nowarn.
Until 2.13.1, there was no summary under -nowarn.
Let -nowarn mean -Xmaxwarns 0 (to mean show me no warnings)
and additionally don't summarize any warnings (including
erroring under -Werror).
Named constants for Reporter.filter
Test that suppression is relaxed in debug mode.
Restore maxwarns after suppressing
Scaladoc also touches nowarn
ConsoleReporter respects nowarn, since PerRunReporting
suppression mechanism has a checkpoint after typer,
such that subsequent warnings are issued directly and
therefore bump the warnings count.
(cherry picked from commit 2a2f4169ca)
Even though these warnings are emitted in the typer phase, the actual
invocation is done at the end of type checking in the root context.
So we should not use the `context.warning` method, as it injects
`context.owner` as the warning site, which is always the root symbol.
(cherry picked from commit a466056367)
- echo without Position parameter to ContextReporter, used in splain
- StoreReporter.Info type/value aliases (scalameta, scapegoat)
- make `info0` deprecatedOverriding instead of final (scalameta)
(cherry picked from commit b5d951be1e)
Integrate the fantastic [silencer](https://github.com/ghik/silencer)
compiler plugin by @ghik into the compiler, which allows suppressing
warnings locally using he `@nowarn` annotation.
The `@nowarn` annotation suppresses warnings within the scope covered by
the annotation.
- `@nowarn def foo = ...`, `@nowarn class C { ... }` suppress
warnings in a definition
- `expression: @nowarn` suppress warnings in a specific expression
The annotation can be configured to filter selected warnings, for
example `@nowarn("cat=deprecation")` only suppresses deprecation
warnings. The filter configuration syntax is the same as in `-Wconf`.
MiMa exception for addition of `scala.annotation.nowarn`
Reporting warnings is now delayed until after typer, because the typer
collects `@nowarn` annotations.
If we stop before typer (e.g., because there are errors in the parser),
all warnings are shown, even if they are enclosed in `@silent`.
If a phase before typer has both errors and warnings, all errors are
printed before the warnings.
(cherry picked from commit 02bce3d609)
Warnings are assigned a category.
Warnings can be filtered by category, by message regex, by site where
they are issued, and by source path. Deprecations can additionally be
filtered by origin (deprecated definition) and `since` version.
Filtered warnings can be reported as error, warning, info, summary
(like deprecations) or silent.
Adds a `-rootdir` compiler flag. It is used to relativize file paths
when using source filters (`-Wconf:src=some/source/File.scala:s`).
There might be other uses for it in the future.
Unchecked warnings are now all shown by default (they were summarized
like deprecations before).
The `-deprecation`, `-feature` and `-unchecked` settings are no longer
directly used in the compiler, they are shortcuts for specific `Wconf`
configurations. The compiler only looks at `-Wconf`.
Message filtering is performed in `global.currentRun.reporting`, not
in the `Global.reporter`. The reasons are:
- Separation of concerns: `Reporter`s worry about how to do reporting,
removing duplicate messages.
- Custom `Reporter`s are used by sbt, silencer, REPL, etc. It's too
hard to do the necessary changes to the `Reporter` interface.
- The `Wconf` setting could change between compiler runs.
`currentRun.reporting` respects those changes.
So all warnings in the compiler should go through `global.runReporting`
(which is the same as `global.currentRun.reporting`). This method takes
four parameters: pos, msg, category (new), site (new). The site is
usually `context.owner` (in the frontend) or `currentOwner` (in
transformations).
`Context` has a `warn` method with 3 parameters (pos, msg, category) and
inserts the `owner` as `site`, so this is used in the frontend (context
reporters are also used to support silent mode / trying twice).
The `global.warning` method is deprecated and no longer used.
There are a few calls to `Reporter.warning` left in the codebase where
no `runReporting` is reachable, I think they are all OK not to
categorize / allow filtering. E.g., when running Scaladoc
```
reporter.warning(null, "Plugins are not available when using Scaladoc")
```
(cherry picked from commit 39d3b3a93c)
Prevents `ClassCastException` in some GADT scenarios
and makes valid code compile in others.
The parent context tree could be the case def itself.
In that case creating a child context with the same tree
breaks the logic to restore saved type bounds in `typedCase`,
because `enclosingCaseDef` returns the child instead of the parent.
This leads to saving modified bounds in the child context
but later trying and failing to restore them in the parent context.
The leaked bounds later cause type errors in the best case
or propagate incorrect information to erasure in the worst case.
Using the tree of the unapply itself for the child context
means that `enclosingCaseDef` will return the parent context.