Skip to content

Commit 5843faa

Browse files
committed
Fix #4574: Don't generate inline accessor for constants
1 parent cf7b589 commit 5843faa

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object PostTyper {
1717

1818
/** A macro transform that runs immediately after typer and that performs the following functions:
1919
*
20-
* (1) Add super accessors and protected accessors (@see SuperAccessors)
20+
* (1) Add super accessors (@see SuperAccessors)
2121
*
2222
* (2) Convert parameter fields that have the same name as a corresponding
2323
* public parameter field in a superclass to a forwarder to the superclass

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ object Inliner {
5353
*/
5454
def needsAccessor(sym: Symbol)(implicit ctx: Context) =
5555
sym.isTerm &&
56+
!sym.info.widenTermRefExpr.isInstanceOf[ConstantType] &&
5657
(sym.is(AccessFlags) || sym.privateWithin.exists) &&
5758
!sym.isContainedIn(inlineSym)
5859

tests/pos/i4754.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Foo {
2+
private final val C = "Constant"
3+
}
4+
5+
class Foo {
6+
import Foo._
7+
inline def foo(x: Int): Boolean = x == C.length
8+
}
9+
10+
class Test {
11+
(new Foo).foo(1)
12+
}

0 commit comments

Comments
 (0)