Skip to content

Commit b1dea8f

Browse files
author
Szymon Rodziewicz
committed
Draft fixes
1 parent 460daf5 commit b1dea8f

File tree

8 files changed

+27
-23
lines changed

8 files changed

+27
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ object Implicits:
559559
else
560560
reasons.mkString
561561

562-
def explanation(using Context) = em"Failed to synthesize implicit of type ${clarify(expectedType)}: ${formatReasons}"
562+
def explanation(using Context) = em"Failed to synthesize an instance of type ${clarify(expectedType)}: ${formatReasons}"
563563

564564
end Implicits
565565

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ import transform.SyntheticMembers._
1717
import util.Property
1818
import ast.Trees.genericEmptyTree
1919
import annotation.{tailrec, constructorOnly}
20+
import ast.tpd._
21+
import Synthesizer._
2022

2123
/** Synthesize terms for special classes */
2224
class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
23-
import ast.tpd._
2425

25-
/** Tuple used to store the synthesis result with a list of errors */
26-
private type TreeWithErrors = (Tree, List[String])
27-
private def withNoErrors(tree: Tree): TreeWithErrors = (tree, List.empty)
28-
29-
private val EmptyTreeNoError: TreeWithErrors = withNoErrors(EmptyTree)
30-
private def orElse(treeWithErrors1: TreeWithErrors, treeWithErrors2: => TreeWithErrors): TreeWithErrors = treeWithErrors1 match
31-
case (tree, errors) if tree eq genericEmptyTree => (treeWithErrors2._1, treeWithErrors2._2 ::: errors)
32-
case _ => treeWithErrors1
33-
3426
/** Handlers to synthesize implicits for special types */
3527
type SpecialHandler = (Type, Span) => Context ?=> TreeWithErrors
3628
private type SpecialHandlers = List[(ClassSymbol, SpecialHandler)]
@@ -620,3 +612,15 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
620612
recur(specialHandlers)
621613

622614
end Synthesizer
615+
616+
object Synthesizer:
617+
618+
/** Tuple used to store the synthesis result with a list of errors */
619+
type TreeWithErrors = (Tree, List[String])
620+
private def withNoErrors(tree: Tree): TreeWithErrors = (tree, List.empty)
621+
622+
private val EmptyTreeNoError: TreeWithErrors = withNoErrors(EmptyTree)
623+
private def orElse(treeWithErrors1: TreeWithErrors, treeWithErrors2: => TreeWithErrors): TreeWithErrors = treeWithErrors1 match
624+
case (tree, errors) if tree eq genericEmptyTree => (treeWithErrors2._1, treeWithErrors2._2 ::: errors)
625+
case _ => treeWithErrors1
626+
end Synthesizer

tests/neg/i14432.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Error: tests/neg/i14432.scala:13:33 ---------------------------------------------------------------------------------
22
13 |val mFoo = summon[Mirror.Of[Foo]] // error: no mirror found
33
| ^
4-
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
4+
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.

tests/neg/i14432a.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Error: tests/neg/i14432a.scala:14:43 --------------------------------------------------------------------------------
22
14 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror found
33
| ^
4-
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
4+
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.

tests/neg/i14432b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Error: tests/neg/i14432b.scala:15:43 --------------------------------------------------------------------------------
22
15 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror found
33
| ^
4-
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
4+
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.

tests/neg/i14432c.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
-- Error: tests/neg/i14432c.scala:16:43 --------------------------------------------------------------------------------
1010
16 | val mFoo = summon[Mirror.Of[example.Foo]] // error: no mirror
1111
| ^
12-
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
12+
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.

tests/neg/i14432d.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-- Error: tests/neg/i14432d.scala:17:45 --------------------------------------------------------------------------------
22
17 | val mFoo = summon[Mirror.Of[example.Foo]] // error
33
| ^
4-
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
4+
|No given instance of type deriving.Mirror.Of[example.Foo] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[example.Foo]: Constructor of class Foo is unnaccessible from the calling scope.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
-- Error: tests/neg/mirror-synthesis-errors.scala:21:32 ----------------------------------------------------------------
22
21 |val testA = summon[Mirror.Of[A]] // error: Not a sealed trait
33
| ^
4-
|No given instance of type deriving.Mirror.Of[A] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[A]: trait A is not a sealed trait
4+
|No given instance of type deriving.Mirror.Of[A] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[A]: trait A is not a sealed trait
55
-- Error: tests/neg/mirror-synthesis-errors.scala:22:32 ----------------------------------------------------------------
66
22 |val testC = summon[Mirror.Of[C]] // error: Does not have subclasses
77
| ^
8-
|No given instance of type deriving.Mirror.Of[C] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[C]: trait C does not have subclasses
8+
|No given instance of type deriving.Mirror.Of[C] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[C]: trait C does not have subclasses
99
-- Error: tests/neg/mirror-synthesis-errors.scala:23:32 ----------------------------------------------------------------
1010
23 |val testD = summon[Mirror.Of[D]] // error: child SubD takes more than one parameter list
1111
| ^
12-
|No given instance of type deriving.Mirror.Of[D] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[D]: class D's child class SubD is not a generic product because class SubD takes more than one parameter list
12+
|No given instance of type deriving.Mirror.Of[D] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[D]: class D's child class SubD is not a generic product because class SubD takes more than one parameter list
1313
-- Error: tests/neg/mirror-synthesis-errors.scala:24:38 ----------------------------------------------------------------
1414
24 |val testSubD = summon[Mirror.Of[SubD]] // error: takes more than one parameter list
1515
| ^
16-
|No given instance of type deriving.Mirror.Of[SubD] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[SubD]: class SubD is not a sealed class
16+
|No given instance of type deriving.Mirror.Of[SubD] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[SubD]: class SubD is not a sealed class
1717
-- Error: tests/neg/mirror-synthesis-errors.scala:25:32 ----------------------------------------------------------------
1818
25 |val testE = summon[Mirror.Of[E]] // error: Not an abstract class
1919
| ^
20-
|No given instance of type deriving.Mirror.Of[E] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[E]: class E is not an abstract class
20+
|No given instance of type deriving.Mirror.Of[E] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[E]: class E is not an abstract class
2121
-- Error: tests/neg/mirror-synthesis-errors.scala:26:32 ----------------------------------------------------------------
2222
26 |val testF = summon[Mirror.Of[F]] // error: No children
2323
| ^
24-
|No given instance of type deriving.Mirror.Of[F] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[F]: trait F does not have subclasses
24+
|No given instance of type deriving.Mirror.Of[F] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[F]: trait F does not have subclasses
2525
-- Error: tests/neg/mirror-synthesis-errors.scala:27:36 ----------------------------------------------------------------
2626
27 |val testG = summon[Mirror.Of[Foo.G]] // error: Has anonymous subclasses
2727
| ^
28-
|No given instance of type deriving.Mirror.Of[Foo.G] was found for parameter x of method summon in object Predef. Failed to synthesize implicit of type deriving.Mirror.Of[Foo.G]: trait G has anonymous or inaccessible subclasses
28+
|No given instance of type deriving.Mirror.Of[Foo.G] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Foo.G]: trait G has anonymous or inaccessible subclasses

0 commit comments

Comments
 (0)