Skip to content

Commit 4694863

Browse files
aherlihyWojciechMazur
authored andcommitted
Add explanation for NotClassType error message
Fixes #14175 [Cherry-picked 00b6fb4]
1 parent 0d70764 commit 4694863

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/reporting/messages.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,11 @@ extends SyntaxMsg(TargetNameOnTopLevelClassID):
27492749
class NotClassType(tp: Type)(using Context)
27502750
extends TypeMsg(NotClassTypeID), ShowMatchTrace(tp):
27512751
def msg(using Context) = i"$tp is not a class type"
2752-
def explain(using Context) = ""
2752+
def explain(using Context) =
2753+
i"""A class type includes classes and traits in a specific order. Defining a class, even an anonymous class,
2754+
|requires specifying a linearization order for the traits it extends. For example, `A & B` is not a class type
2755+
|because it doesn't specify which trait takes precedence, A or B. For more information about class types, please see the Scala Language Specification.
2756+
|Class types also can't have refinements."""
27532757

27542758
class NotConstant(suffix: String, tp: Type)(using Context)
27552759
extends TypeMsg(NotConstantID), ShowMatchTrace(tp):

Diff for: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check

+16
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
14 | val b = js.constructorOf[NativeJSObject.type] // error
77
| ^^^^^^^^^^^^^^^^^^^
88
| NativeJSObject.type is not a class type
9+
|
10+
| longer explanation available when compiling with `-explain`
911
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:27 -----------------------------
1012
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
1113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1214
| NativeJSClass & NativeJSTrait is not a class type
15+
|
16+
| longer explanation available when compiling with `-explain`
1317
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:17:27 -----------------------------
1418
17 | val d = js.constructorOf[NativeJSClass { def bar: Int }] // error
1519
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1620
| NativeJSClass{def bar: Int} is not a class type
21+
|
22+
| longer explanation available when compiling with `-explain`
1723
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:19:27 -----------------------------------------
1824
19 | val e = js.constructorOf[JSTrait] // error
1925
| ^^^^^^^
@@ -22,19 +28,29 @@
2228
20 | val f = js.constructorOf[JSObject.type] // error
2329
| ^^^^^^^^^^^^^
2430
| JSObject.type is not a class type
31+
|
32+
| longer explanation available when compiling with `-explain`
2533
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:27 -----------------------------
2634
22 | val g = js.constructorOf[JSClass with JSTrait] // error
2735
| ^^^^^^^^^^^^^^^^^^^^
2836
| JSClass & JSTrait is not a class type
37+
|
38+
| longer explanation available when compiling with `-explain`
2939
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:23:27 -----------------------------
3040
23 | val h = js.constructorOf[JSClass { def bar: Int }] // error
3141
| ^^^^^^^^^^^^^^^^^^^^^^^^
3242
| JSClass{def bar: Int} is not a class type
43+
|
44+
| longer explanation available when compiling with `-explain`
3345
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:25:42 -----------------------------
3446
25 | def foo[A <: js.Any] = js.constructorOf[A] // error
3547
| ^
3648
| A is not a class type
49+
|
50+
| longer explanation available when compiling with `-explain`
3751
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:26:66 -----------------------------
3852
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorOf[A] // error
3953
| ^
4054
| A is not a class type
55+
|
56+
| longer explanation available when compiling with `-explain`

Diff for: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check

+16
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
14 | val b = js.constructorTag[NativeJSObject.type] // error
77
| ^
88
| NativeJSObject.type is not a class type
9+
|
10+
| longer explanation available when compiling with `-explain`
911
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:61 ----------------------------
1012
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
1113
| ^
1214
| NativeJSClass & NativeJSTrait is not a class type
15+
|
16+
| longer explanation available when compiling with `-explain`
1317
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:17:59 ----------------------------
1418
17 | val d = js.constructorTag[NativeJSClass { def bar: Int }] // error
1519
| ^
1620
| NativeJSClass{def bar: Int} is not a class type
21+
|
22+
| longer explanation available when compiling with `-explain`
1723
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:19:36 ----------------------------------------
1824
19 | val e = js.constructorTag[JSTrait] // error
1925
| ^
@@ -22,19 +28,29 @@
2228
20 | val f = js.constructorTag[JSObject.type] // error
2329
| ^
2430
| JSObject.type is not a class type
31+
|
32+
| longer explanation available when compiling with `-explain`
2533
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:49 ----------------------------
2634
22 | val g = js.constructorTag[JSClass with JSTrait] // error
2735
| ^
2836
| JSClass & JSTrait is not a class type
37+
|
38+
| longer explanation available when compiling with `-explain`
2939
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:23:53 ----------------------------
3040
23 | val h = js.constructorTag[JSClass { def bar: Int }] // error
3141
| ^
3242
| JSClass{def bar: Int} is not a class type
43+
|
44+
| longer explanation available when compiling with `-explain`
3345
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:25:45 ----------------------------
3446
25 | def foo[A <: js.Any] = js.constructorTag[A] // error
3547
| ^
3648
| A is not a class type
49+
|
50+
| longer explanation available when compiling with `-explain`
3751
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:26:69 ----------------------------
3852
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorTag[A] // error
3953
| ^
4054
| A is not a class type
55+
|
56+
| longer explanation available when compiling with `-explain`

Diff for: tests/neg/classOf.check

+6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
6 | def f1[T] = classOf[T] // error
33
| ^
44
| T is not a class type
5+
|
6+
| longer explanation available when compiling with `-explain`
57
-- [E170] Type Error: tests/neg/classOf.scala:7:32 ---------------------------------------------------------------------
68
7 | def f2[T <: String] = classOf[T] // error
79
| ^
810
| T is not a class type
911
|
1012
| where: T is a type in method f2 with bounds <: String
13+
|
14+
| longer explanation available when compiling with `-explain`
1115
-- [E170] Type Error: tests/neg/classOf.scala:9:18 ---------------------------------------------------------------------
1216
9 | val y = classOf[C { type I = String }] // error
1317
| ^^^^^^^^^^^^^^^^^^^^^
1418
| Test.C{type I = String} is not a class type
19+
|
20+
| longer explanation available when compiling with `-explain`

Diff for: tests/neg/i13808.check

+4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
33
| ^^^^^^^^^^
44
| OpaqueTypes.OpaqueType is not a class type
5+
|
6+
| longer explanation available when compiling with `-explain`
57
-- [E170] Type Error: tests/neg/i13808.scala:13:49 ---------------------------------------------------------------------
68
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
79
| ^^^
810
| FooModule.Foo is not a class type
11+
|
12+
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)