summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala28
-rw-r--r--test/files/neg/t3649.check8
-rw-r--r--test/files/neg/t3649.scala1
3 files changed, 24 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index 468e2a6b20..b082cd78f5 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -369,19 +369,23 @@ trait NamesDefaults { self: Analyzer =>
if (givenArgs.length < params.length) {
val (missing, positional) = missingParams(givenArgs, params)
if (missing forall (_.hasDefaultFlag)) {
- val defaultArgs = missing map (p => {
- var default1 = qual match {
- case Some(q) => gen.mkAttributedSelect(q.duplicate, defaultGetter(p, context))
- case None => gen.mkAttributedRef(defaultGetter(p, context))
+ val defaultArgs = missing flatMap (p => {
+ val defGetter = defaultGetter(p, context)
+ if (defGetter == NoSymbol) None // prevent crash in erroneous trees, #3649
+ else {
+ var default1 = qual match {
+ case Some(q) => gen.mkAttributedSelect(q.duplicate, defGetter)
+ case None => gen.mkAttributedRef(defGetter)
- }
- default1 = if (targs.isEmpty) default1
- else TypeApply(default1, targs.map(_.duplicate))
- val default2 = (default1 /: previousArgss)((tree, args) =>
- Apply(tree, args.map(_.duplicate)))
- atPos(pos) {
- if (positional) default2
- else AssignOrNamedArg(Ident(p.name), default2)
+ }
+ default1 = if (targs.isEmpty) default1
+ else TypeApply(default1, targs.map(_.duplicate))
+ val default2 = (default1 /: previousArgss)((tree, args) =>
+ Apply(tree, args.map(_.duplicate)))
+ Some(atPos(pos) {
+ if (positional) default2
+ else AssignOrNamedArg(Ident(p.name), default2)
+ })
}
})
(givenArgs ::: defaultArgs, Nil)
diff --git a/test/files/neg/t3649.check b/test/files/neg/t3649.check
index 07ff1bf3ac..76d68fa3b7 100644
--- a/test/files/neg/t3649.check
+++ b/test/files/neg/t3649.check
@@ -1,4 +1,10 @@
t3649.scala:1: error: C is already defined as (compiler-generated) case class companion object C
object T { class C(s: String = ""); val C = 0 }
^
-one error found
+t3649.scala:2: error: C is already defined as (compiler-generated) case class companion object C
+object U { class C(val s: String = ""); val C = new C() {} }
+ ^
+t3649.scala:2: error: not enough arguments for constructor C: (s: String)U.C
+object U { class C(val s: String = ""); val C = new C() {} }
+ ^
+three errors found
diff --git a/test/files/neg/t3649.scala b/test/files/neg/t3649.scala
index 02e020001a..2aaff96100 100644
--- a/test/files/neg/t3649.scala
+++ b/test/files/neg/t3649.scala
@@ -1 +1,2 @@
object T { class C(s: String = ""); val C = 0 }
+object U { class C(val s: String = ""); val C = new C() {} }