Skip to content
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

Fix encoding of setters on anonymous classes with structural types #13707

Merged
merged 1 commit into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Expand Up @@ -3894,6 +3894,9 @@ object Parsers {
val stats = new ListBuffer[Tree]
def checkLegal(tree: Tree): List[Tree] =
val problem = tree match
case tree: ValDef if tree.mods.is(Mutable) =>
i"""refinement cannot be a mutable var.
|You can use an explicit getter ${tree.name} and setter ${tree.name}_= instead"""
case tree: MemberDef if !(tree.mods.flags & ModifierFlags).isEmpty =>
i"refinement cannot be ${(tree.mods.flags & ModifierFlags).flagStrings().mkString("`", "`, `", "`")}"
case tree: DefDef if tree.termParamss.nestedExists(!_.rhs.isEmpty) =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Dynamic.scala
Expand Up @@ -186,7 +186,7 @@ trait Dynamic {
val base =
untpd.Apply(
untpd.TypedSplice(selectable.select(selectorName)).withSpan(fun.span),
(Literal(Constant(name.toString)) :: Nil).map(untpd.TypedSplice(_)))
(Literal(Constant(name.encode.toString)) :: Nil).map(untpd.TypedSplice(_)))

val scall =
if (vargss.isEmpty) base
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i13703.check
@@ -0,0 +1,5 @@
-- Error: tests/neg/i13703.scala:3:17 ----------------------------------------------------------------------------------
3 |val f: Foo { var i: Int } = new Foo { var i: Int = 0 } // error
| ^^^^^^^^^^
| refinement cannot be a mutable var.
| You can use an explicit getter i and setter i_= instead
5 changes: 5 additions & 0 deletions tests/neg/i13703.scala
@@ -0,0 +1,5 @@
trait Foo extends reflect.Selectable

val f: Foo { var i: Int } = new Foo { var i: Int = 0 } // error

val f2: Foo { val i: Int; def i_=(x: Int): Unit } = new Foo { var i: Int = 0 } // OK
5 changes: 5 additions & 0 deletions tests/run/i13703.scala
@@ -0,0 +1,5 @@
trait Foo extends reflect.Selectable

@main def Test: Unit =
val f = new Foo { var i: Int = 0 }
f.i = 1