Skip to content

Commit 611f8ee

Browse files
authored
Merge pull request #2904 from dotty-staging/fix-#2564
Fix #2564: Do not create ill-formed <init> accessors
2 parents 4ecb1f7 + c5b176f commit 611f8ee

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,14 @@ 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+
if (methPart.symbol.isConstructor && needsAccessor(methPart.symbol)) {
148+
ctx.error("Cannot use private constructors in inline methods", tree.pos)
149+
tree // TODO: create a proper accessor for the private constructor
150+
} else {
151+
addAccessor(tree, methPart, targs, argss,
152+
accessedType = methPart.tpe.widen,
153+
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
154+
}
150155
} else {
151156
// TODO: Handle references to non-public types.
152157
// 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)