From 2a204977d45a97424b46492308167d1668f4882c Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Fri, 25 Mar 2022 15:48:55 -0700 Subject: [PATCH] Refrain from adding ctor to class from ct.sym --- .../scala/tools/nsc/settings/ScalaSettings.scala | 2 +- .../tools/nsc/symtab/classfile/ClassfileParser.scala | 6 +++++- test/files/neg/t12565.check | 4 ++++ test/files/neg/t12565.scala | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t12565.check create mode 100644 test/files/neg/t12565.scala diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 8e6ac5db2e04..1a5587960a54 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -90,7 +90,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett // TODO validate release <= java.specification.version } } withAbbreviation "--release" - def releaseValue: Option[String] = Option(release.value).filter(_ != "") + def releaseValue: Option[String] = Option(release.value).filter(_ != "") // release.valueSetByUser /** * -X "Advanced" settings diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index da93a90d72c1..0c627299ca52 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -549,7 +549,11 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) { val needsConstructor = ( !sawPrivateConstructor && !(instanceScope containsName nme.CONSTRUCTOR) - && ((sflags & INTERFACE) == 0 || (sflags | JAVA_ANNOTATION) != 0) + && ((sflags & INTERFACE) == 0 || (sflags & JAVA_ANNOTATION) != 0) + && { + val isSig = file.name.endsWith(".sig") + !isSig + } ) if (needsConstructor) instanceScope enter clazz.newClassConstructor(NoPosition) diff --git a/test/files/neg/t12565.check b/test/files/neg/t12565.check new file mode 100644 index 000000000000..b67443b9b545 --- /dev/null +++ b/test/files/neg/t12565.check @@ -0,0 +1,4 @@ +t12565.scala:5: error: java.time.Instant does not have a constructor + def f = new java.time.Instant + ^ +1 error diff --git a/test/files/neg/t12565.scala b/test/files/neg/t12565.scala new file mode 100644 index 000000000000..6336f90a4dd4 --- /dev/null +++ b/test/files/neg/t12565.scala @@ -0,0 +1,9 @@ +// scalac: -Werror --release 8 +// javaVersion: 9+ + +class C { + def f = new java.time.Instant +} +object Test extends App { + println(new C().f) +}