Skip to content

Instantly share code, notes, and snippets.

View lrytz's full-sized avatar
🦉

Lukas Rytz lrytz

🦉
View GitHub Profile
@lrytz
lrytz / wconf.md
Last active November 24, 2020 16:32

Configuring and suppressing warnings in Scala

Scala 2.13.2 and 2.12.13 introduced the -Wconf compiler flag to globally configure reporting of warnings, and the @nowarn annotation to locally suppress them. Having more control over compiler warnings makes them a lot more valuable:

  • In projects where the build log shows a lot of of warnings that are mostly ignored, new helpful warnings can easily go undetected. The new functionality can be used to clean up the build log with manageable efforts and potentially enable fatal warning (-Werror in 2.13, -Xfatal-warnings in 2.12). This has happened for example in Scala compiler and standard library projects in the past few months.
  • Projects that already use fatal warnings get better utilities to work around corner cases where a warning cannot be avoided. This can allow further -Xlint checks to be enabled.

In this post we go through the mechanics of configuring warnigns and also look at the new @nowarn annotation.

Warnings from the Scala compil

@lrytz
lrytz / A.scala
Last active October 15, 2020 08:01
jsr45 scala
object A {
def main(args: Array[String]): Unit = {
val testVar = "hai"
val res = B.foo(testVar)
println(res)
}
}
@lrytz
lrytz / Test.java
Last active October 1, 2020 07:55
ForkJoinPool JDK 11+
import java.util.concurrent.*;
public class Test {
static boolean triggerIssue = true;
static ForkJoinPool fjp;
static void hotSleep(int ms) {
long until = System.nanoTime() + ms*1000_000;
while (System.nanoTime() < until) { }
diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala
index 9187c7c041..704a0f7f3e 100644
--- a/src/library/scala/collection/Map.scala
+++ b/src/library/scala/collection/Map.scala
@@ -33,7 +33,7 @@ trait Map[K, +V]
case that: Map[K, _] =>
(this eq that) ||
(that canEqual this) &&
- (this.size == that.size) && {
+ (this.sizeCompare(that) == 0) && {
sbt:root> partest --srcpath async test/async/jvm/live.scala
Partest version: 2.13.3-20200619-135756-79afa3f
Compiler under test: $baseDir/compiler
Scala version is: Scala compiler version 2.13.3-20200619-135756-79afa3f -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.
Scalac options are: -Wconf:cat=unchecked&msg=The outer reference in this type test cannot be checked at run time.:s -Wconf:cat=optimizer:is
Compilation Path: /Users/luc/scala/scala13/target/test/it-classes:$baseDir/test:$baseDir/compiler:$baseDir/library:$baseDir/reflect:$baseDir/interactive:$baseDir/repl-frontend:$baseDir/repl:$baseDir/scalap:$baseDir/partest:$baseDir/scaladoc:$baseDir/testkit:/Users/luc/scala/scala13/target/partest-javaagent/scala-partest-javaagent-2.13.3-bin-SNAPSHOT.jar:/Users/luc/Library/Caches/Coursier/v1/http/127.0.0.1%3A8081/artifactory/scala-ci-virtual/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/luc/Library/Caches/Coursier/v1/http/127.0.0.1%3A8081/artifactory/scala-ci-virtual/org/scala-sbt
@lrytz
lrytz / content.txt
Last active April 16, 2020 13:51
scala-parallel-collections jar
➜ scala-parallel-collections git:(master) unzip -l /Users/luc/.ivy2/local/org.scala-lang.modules/scala-parallel-collections_2.13/0.1.2+107-ca1a2942-SNAPSHOT/bundles/scala-parallel-collections_2.13.jar | c4 | sort
----
META-INF/
META-INF/MANIFEST.MF
Name
scala-parallel-collections.properties
scala/
given object intOrd extends Ord[Int] {}
given object _ extends Ord[Int] {}
given object extends Ord[Int] {}
given val intOrd: Ord[Int] = ...
given val _ : Ord[Int] = ...
given val : Ord[Int] = ...
given def intListOrd(using Ord[Int]): Ord[List[Int]] = ...
given def _(using Ord[Int]): Ord[List[Int]] = ...
➜ sandbox git:(2.13.x) ~/Applications/bin/scala-runners/scala -212x
Welcome to Scala 2.12.11-bin-d1e9ac0 (Java HotSpot(TM) 64-Bit GraalVM EE 19.2.1, Java 1.8.0_231).
Type in expressions for evaluation. Or try :help.
scala> case class K(var x: Int)
defined class K
scala> val k = K(1)
k: K = K(1)
@lrytz
lrytz / A.asm
Last active January 13, 2020 13:39
// class version 52.0 (52)
// access flags 0x601
public abstract interface A {
// compiled from: Test.scala
@Lscala/reflect/ScalaSignature;(bytes="\u0006\u0005a1qa\u0001\u0003\u0011\u0002\u0007\u0005q\u0001C\u0003\u000f\u0001\u0011\u0005q\u0002C\u0004\u0014\u0001\u0009\u0007I\u0011\u0001\u000b\u0003\u0003\u0005S\u0011!B\u0001\u0008y\u0015l\u0007\u000f^=?\u0007\u0001\u0019\"\u0001\u0001\u0005\u0011\u0005%aQ\"\u0001\u0006\u000b\u0003-\u0009Qa]2bY\u0006L!!\u0004\u0006\u0003\r\u0005s\u0017PU3g\u0003\u0019!\u0013N\\5uIQ\u0009\u0001\u0003\u0005\u0002\n#%\u0011!C\u0003\u0002\u0005+:LG/A\u0001y+\u0005)\u0002CA\u0005\u0017\u0013\u00099\"BA\u0002J]R\u0004")
ATTRIBUTE ScalaSig : unknown