8000 Put tut:fail for code block that should fail to compile · Nydhal/scala.github.com@2dfa9c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2dfa9c4

Browse files
committed
Put tut:fail for code block that should fail to compile
1 parent 94fad22 commit 2dfa9c4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tutorials/tour/case-classes.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ val title = emailFromJohn.title
4141
println(title) // prints "Greetings From John!"
4242
```
4343

44-
With case classes, you cannot mutate their fields directly. Instead, you make a copy using the `copy` method.
45-
As seen below, you can replace just some of the fields:
44+
With case classes, you cannot mutate their fields directly.
4645

47-
```tut
46+
```tut:fail
4847
emailFromJohn.title = "Goodbye From John!" // This is a compilation error. We cannot assign another value to val fields, which all case classes fields are by default.
48+
```
4949

50+
Instead, you make a copy using the `copy` method. As seen below, you can replace just some of the fields:
51+
52+
```tut
5053
val editedEmail = emailFromJohn.copy(title = "I am learning Scala!", body = "It's so cool!")
5154
5255
println(emailFromJohn) // prints "Email(john.doe@mail.com,Greetings From John!,Hello World!)"

0 commit comments

Comments
 (0)
0