Skip to content

Fix #4739: Exempt combinations of Java fields and methods as double defs #5931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ object Contexts {
* - as scope: The parameters of the auxiliary constructor.
*/
def thisCallArgContext: Context = {
assert(owner.isClassConstructor)
val constrCtx = outersIterator.dropWhile(_.outer.owner == owner).next()
superOrThisCallContext(owner, constrCtx.scope)
.setTyperState(typerState)
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
* otherwise the current context.
*/
def argCtx(app: untpd.Tree)(implicit ctx: Context): Context =
if (untpd.isSelfConstrCall(app)) ctx.thisCallArgContext else ctx
if (ctx.owner.isClassConstructor && untpd.isSelfConstrCall(app)) ctx.thisCallArgContext
else ctx

/** Typecheck application. Result could be an `Apply` node,
* or, if application is an operator assignment, also an `Assign` or
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,10 @@ trait Checking {
def checkDecl(decl: Symbol): Unit = {
for (other <- seen(decl.name)) {
typr.println(i"conflict? $decl $other")
if (decl.matches(other)) {
def javaFieldMethodPair =
decl.is(JavaDefined) && other.is(JavaDefined) &&
decl.is(Method) != other.is(Method)
if (decl.matches(other) && !javaFieldMethodPair) {
def doubleDefError(decl: Symbol, other: Symbol): Unit =
if (!decl.info.isErroneous && !other.info.isErroneous)
ctx.error(DoubleDeclaration(decl, other), decl.sourcePos)
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i5004.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object i0 {
1 match {
def this(): Int // error // error
def this() // error
} // error
}
6 changes: 6 additions & 0 deletions tests/pos/i4739.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class i4739 {
int foo;
int foo() {
return this.foo;
}
}