Skip to content

Fix #2631: Add custom error message #3802

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
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ class Typer extends Namer
}
else if (name.toTermName == nme.ERROR)
UnspecifiedErrorType
else
else if (ctx.owner.isConstructor && ctx.owner.owner.unforcedDecls.lookup(tree.name).exists) {
// If the field existed but was not found we assume that
// we where in the context of an argument of the super constructor
errorType(ex"$tree is not accessible from super constructor arguments", tree.pos)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter do you think this condition is enough?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you check ctx.mode.is(InSuperCall) ? (The name is misleading, it's set for both this- and super-call, see the method superOrThisCallContext)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, don't say "super constructor", a this call is not a super call, it's just a constructor call

} else
errorType(new MissingIdent(tree, kind, name.show), tree.pos)

val tree1 = ownType match {
Expand Down
4 changes: 4 additions & 0 deletions compiler/test-resources/repl/i2631
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
| ^^^
| foo is not accessible from super constructor arguments