Skip to content

Commit f00cda8

Browse files
committed
Fix #2564: Do not create ill-formed <init> accessors
1 parent d7faafa commit f00cda8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ object Inliner {
144144
case _: Apply | _: TypeApply | _: RefTree if needsAccessor(tree.symbol) =>
145145
if (tree.isTerm) {
146146
val (methPart, targs, argss) = decomposeCall(tree)
147-
addAccessor(tree, methPart, targs, argss,
148-
accessedType = methPart.tpe.widen,
149-
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
147+
val mSym = methPart.symbol
148+
if (mSym.isConstructor && (mSym.is(Private) || mSym.privateWithin.exists)) {
149+
ctx.error("Cannot use private constructors in inline methods", tree.pos)
150+
tree // TODO: create a proper accessor for the private constructor
151+
} else {
152+
addAccessor(tree, methPart, targs, argss,
153+
accessedType = methPart.tpe.widen,
154+
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
155+
}
150156
} else {
151157
// TODO: Handle references to non-public types.
152158
// This is quite tricky, as such types can appear anywhere, including as parts

tests/neg/i2564.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
inline def bar = new Bar // error
3+
class Bar private[Foo]()
4+
}

tests/neg/i2564b.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo private() {
2+
inline def foo = new Foo // error
3+
}

0 commit comments

Comments
 (0)