Skip to content

Commit c709511

Browse files
committed
Fix #5588: Add regression test
1 parent 7b64780 commit c709511

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/pos/i5588a.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
object TestMain {
2+
def main(args: Array[String]): Unit = {
3+
testExtensionProperty()
4+
}
5+
6+
case class Foo(var foo: String)
7+
8+
object fooExt {
9+
// define `Foo`-extension property with getter and setter delegating to `Foo.foo`
10+
extension (thisFoo: Foo) def fooExt: String = thisFoo.foo
11+
extension (thisFoo: Foo) def fooExt_= (value: String): Unit = { thisFoo.foo = value }
12+
}
13+
14+
def testExtensionProperty(): Unit = {
15+
import fooExt._
16+
val foo = Foo("initVal")
17+
assert(foo.fooExt == "initVal")
18+
foo.fooExt = "updatedVal"
19+
assert(foo.foo == "updatedVal")
20+
assert(foo.fooExt == "updatedVal")
21+
}
22+
}

tests/pos/i5588b.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
object TestMain2 {
2+
def main(args: Array[String]): Unit = {
3+
testExtensionProperty()
4+
}
5+
6+
case class Foo(var foo: String)
7+
8+
implicit object fooExt {
9+
// define `Foo`-extension property with getter and setter delegating to `Foo.foo`
10+
extension (thisFoo: Foo) def fooExt: String = thisFoo.foo
11+
extension (thisFoo: Foo) def fooExt_= (value: String): Unit = { thisFoo.foo = value }
12+
}
13+
14+
def testExtensionProperty(): Unit = {
15+
//import fooExt._
16+
val foo = Foo("initVal")
17+
assert(foo.fooExt == "initVal")
18+
foo.fooExt = "updatedVal"
19+
assert(foo.foo == "updatedVal")
20+
assert(foo.fooExt == "updatedVal")
21+
}
22+
}

0 commit comments

Comments
 (0)