Skip to content

Commit 010bf8e

Browse files
committed
Only check last position, use DoubleDefinition
1 parent b2376f2 commit 010bf8e

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

-16
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,6 @@ object Decorators {
234234
def nestedExists(p: T => Boolean): Boolean = xss match
235235
case xs :: xss1 => xs.exists(p) || xss1.nestedExists(p)
236236
case nil => false
237-
def nestedZipExists(yss: List[List[U]])(f: (T, U) => Boolean): Boolean =
238-
@tailrec def zipExists(p1: List[T], p2: List[U]): Boolean =
239-
p1 match
240-
case h :: t =>
241-
p2 match
242-
case h2 :: t2 => f(h, h2) || zipExists(t, t2)
243-
case _ => false
244-
case _ => false
245-
@tailrec def loop(ps1: List[List[T]], ps2: List[List[U]]): Boolean =
246-
ps1 match
247-
case h :: t =>
248-
ps2 match
249-
case h2 :: t2 => zipExists(h, h2) || loop(t, t2)
250-
case _ => false
251-
case _ => false
252-
loop(xss, yss)
253237
end extension
254238

255239
extension (text: Text)

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ object ErrorReporting {
125125
/** Explain info of symbol `sym` as a member of class `base`.
126126
* @param showLocation if true also show sym's location.
127127
*/
128-
def infoString(sym: Symbol, base: Type, showLocation: Boolean): String = atPhase(Phases.typerPhase) {
128+
def infoString(sym: Symbol, base: Type, showLocation: Boolean): String =
129129
val sym1 = sym.underlyingSymbol
130130
def info = base.memberInfo(sym1)
131131
val infoStr =
@@ -135,7 +135,6 @@ object ErrorReporting {
135135
else if sym1.isTerm then i" of type $info"
136136
else ""
137137
i"${if showLocation then sym1.showLocated else sym1}$infoStr"
138-
}
139138

140139
def infoStringWithLocation(sym: Symbol, base: Type) =
141140
infoString(sym, base, showLocation = true)

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

+15-4
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,21 @@ object RefChecks {
336336
next == other || isInheritedAccessor(next, other)
337337
}
338338

339+
/** Detect any param section where params in last position do not agree isRepeatedParam.
340+
*/
339341
def incompatibleRepeatedParam(member: Symbol, other: Symbol): Boolean =
340-
member.is(Method, butNot = JavaDefined) && other.is(Method, butNot = JavaDefined) && atPhase(typerPhase) {
341-
member.info.paramInfoss.nestedZipExists(other.info.paramInfoss)(_.isRepeatedParam != _.isRepeatedParam)
342-
}
342+
def loop(mParamInfoss: List[List[Type]], oParamInfoss: List[List[Type]]): Boolean =
343+
mParamInfoss match
344+
case Nil => false
345+
case h :: t =>
346+
oParamInfoss match
347+
case Nil => false
348+
case h2 :: t2 => h.nonEmpty && h2.nonEmpty && h.last.isRepeatedParam != h2.last.isRepeatedParam
349+
|| loop(t, t2)
350+
member.is(Method, butNot = JavaDefined)
351+
&& other.is(Method, butNot = JavaDefined)
352+
&& atPhase(typerPhase):
353+
loop(member.info.paramInfoss, other.info.paramInfoss)
343354

344355
/* Check that all conditions for overriding `other` by `member`
345356
* of class `clazz` are met.
@@ -502,7 +513,7 @@ object RefChecks {
502513
else if member.is(Exported) then
503514
overrideError("cannot override since it comes from an export")
504515
else if incompatibleRepeatedParam(member, other) then
505-
overrideError("cannot override because erased signatures conflict in repeated parameter")
516+
report.error(DoubleDefinition(member, other, clazz), member.srcPos)
506517
else
507518
overrideError("needs `override` modifier")
508519
else if (other.is(AbsOverride) && other.isIncompleteIn(clazz) && !member.is(AbsOverride))

tests/neg/override-scala2-macro.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- [E164] Declaration Error: tests/neg/override-scala2-macro.scala:2:22 ------------------------------------------------
22
2 | override inline def f[A >: Any](args: A*): String = ??? // error
33
| ^
4-
|error overriding method f in class StringContext of type [A >: Any](args: A*): String;
5-
| method f of type [A >: Any](args: A*): String cannot be used here - only Scala-2 macros can override Scala-2 macros
4+
|error overriding method f in class StringContext of type [A >: Any](args: Seq[A]): String;
5+
| method f of type [A >: Any](args: Seq[A]): String cannot be used here - only Scala-2 macros can override Scala-2 macros

0 commit comments

Comments
 (0)