Skip to content

Fix #2564: Do not create ill-formed <init> accessors #2904

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 2 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ object Inliner {
case _: Apply | _: TypeApply | _: RefTree if needsAccessor(tree.symbol) =>
if (tree.isTerm) {
val (methPart, targs, argss) = decomposeCall(tree)
addAccessor(tree, methPart, targs, argss,
accessedType = methPart.tpe.widen,
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
val mSym = methPart.symbol
if (mSym.isConstructor && (mSym.is(Private) || mSym.privateWithin.exists)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check privateWithin, is it subsumed by the private check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so too but when trying it out I found that it was not the case. Should it be? Did I stumble on another bug?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@nicolasstucki nicolasstucki Jul 24, 2017

Choose a reason for hiding this comment

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

Actually I should use mSym.isConstructor && needsAccessor(mSym)

ctx.error("Cannot use private constructors in inline methods", tree.pos)
tree // TODO: create a proper accessor for the private constructor
} else {
addAccessor(tree, methPart, targs, argss,
accessedType = methPart.tpe.widen,
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
}
} else {
// TODO: Handle references to non-public types.
// This is quite tricky, as such types can appear anywhere, including as parts
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i2564.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Foo {
inline def bar = new Bar // error
class Bar private[Foo]()
}
3 changes: 3 additions & 0 deletions tests/neg/i2564b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo private() {
inline def foo = new Foo // error
}