Skip to content

Commit 11f56d5

Browse files
committed
Commented out a definition that causes a compilation failure.
Signed-off-by: Dean Wampler <[email protected]>
1 parent 3f5f056 commit 11f56d5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/script/scala/progscala3/contexts/typeclass/TypeClassSubtypingProblems.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ list1.map(_.toJSON("object"))
8282
// Well, an infinite recursion occurs!! This is because, for example,
8383
// person.toJSON() will now recursively call the DomainConcept.toJSON
8484
// extension method, instead of the original Person.toJSON.
85+
// Try it yourself; uncomment the following given definition and comment out
86+
// the previous definition of ToJSON[DomainConcept], then rerun this script.
87+
// given ToJSON[DomainConcept]:
88+
// extension (dc: DomainConcept)
89+
// def toJSON(name: String = "", level: Int = 0): String = dc match
90+
// case person: Person => person.toJSON(name, level)
91+
// case address: Address => address.toJSON(name, level)
8592

86-
given ToJSON[DomainConcept]:
87-
extension (dc: DomainConcept)
88-
def toJSON(name: String = "", level: Int = 0): String = dc match
89-
case person: Person => person.toJSON(name, level)
90-
case address: Address => address.toJSON(name, level)
91-
92-
list1.map(_.toJSON()) // BOOM!!
93+
// list1.map(_.toJSON("object")) // BOOM - Stack overflow!!
9394
// END 4

0 commit comments

Comments
 (0)