Skip to content

Commit 9a79c14

Browse files
authored
Update phrasing for NotClassType explain error message (#19635)
Fixes #14175
2 parents 6a795fd + 00b6fb4 commit 9a79c14

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

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

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

docs/_docs/contributing/testing.md

+5
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ checkfiles with the test outputs.
141141
$ sbt
142142
> testCompilation --update-checkfiles
143143
```
144+
Or for ScalaJS
145+
```bash
146+
$ sbt
147+
> sjsCompilerTests/testOnly -- -Ddotty.tests.updateCheckfiles=TRUE
148+
```
144149

145150
Use `--help` to see all the options
146151
```bash

tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check

+16
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
14 | val b = js.constructorOf[NativeJSObject.type] // error
2121
| ^^^^^^^^^^^^^^^^^^^
2222
| NativeJSObject.type is not a class type
23+
|
24+
| longer explanation available when compiling with `-explain`
2325
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:27 -----------------------------
2426
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
2527
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2628
| NativeJSClass & NativeJSTrait is not a class type
29+
|
30+
| longer explanation available when compiling with `-explain`
2731
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:17:27 -----------------------------
2832
17 | val d = js.constructorOf[NativeJSClass { def bar: Int }] // error
2933
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3034
| NativeJSClass{def bar: Int} is not a class type
35+
|
36+
| longer explanation available when compiling with `-explain`
3137
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:19:27 -----------------------------------------
3238
19 | val e = js.constructorOf[JSTrait] // error
3339
| ^^^^^^^
@@ -36,19 +42,29 @@
3642
20 | val f = js.constructorOf[JSObject.type] // error
3743
| ^^^^^^^^^^^^^
3844
| JSObject.type is not a class type
45+
|
46+
| longer explanation available when compiling with `-explain`
3947
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:27 -----------------------------
4048
22 | val g = js.constructorOf[JSClass with JSTrait] // error
4149
| ^^^^^^^^^^^^^^^^^^^^
4250
| JSClass & JSTrait is not a class type
51+
|
52+
| longer explanation available when compiling with `-explain`
4353
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:23:27 -----------------------------
4454
23 | val h = js.constructorOf[JSClass { def bar: Int }] // error
4555
| ^^^^^^^^^^^^^^^^^^^^^^^^
4656
| JSClass{def bar: Int} is not a class type
57+
|
58+
| longer explanation available when compiling with `-explain`
4759
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:25:42 -----------------------------
4860
25 | def foo[A <: js.Any] = js.constructorOf[A] // error
4961
| ^
5062
| A is not a class type
63+
|
64+
| longer explanation available when compiling with `-explain`
5165
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:26:66 -----------------------------
5266
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorOf[A] // error
5367
| ^
5468
| A is not a class type
69+
|
70+
| longer explanation available when compiling with `-explain`

tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check

+16
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
14 | val b = js.constructorTag[NativeJSObject.type] // error
2121
| ^
2222
| NativeJSObject.type is not a class type
23+
|
24+
| longer explanation available when compiling with `-explain`
2325
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:61 ----------------------------
2426
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
2527
| ^
2628
| NativeJSClass & NativeJSTrait is not a class type
29+
|
30+
| longer explanation available when compiling with `-explain`
2731
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:17:59 ----------------------------
2832
17 | val d = js.constructorTag[NativeJSClass { def bar: Int }] // error
2933
| ^
3034
| NativeJSClass{def bar: Int} is not a class type
35+
|
36+
| longer explanation available when compiling with `-explain`
3137
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:19:36 ----------------------------------------
3238
19 | val e = js.constructorTag[JSTrait] // error
3339
| ^
@@ -36,19 +42,29 @@
3642
20 | val f = js.constructorTag[JSObject.type] // error
3743
| ^
3844
| JSObject.type is not a class type
45+
|
46+
| longer explanation available when compiling with `-explain`
3947
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:49 ----------------------------
4048
22 | val g = js.constructorTag[JSClass with JSTrait] // error
4149
| ^
4250
| JSClass & JSTrait is not a class type
51+
|
52+
| longer explanation available when compiling with `-explain`
4353
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:23:53 ----------------------------
4454
23 | val h = js.constructorTag[JSClass { def bar: Int }] // error
4555
| ^
4656
| JSClass{def bar: Int} is not a class type
57+
|
58+
| longer explanation available when compiling with `-explain`
4759
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:25:45 ----------------------------
4860
25 | def foo[A <: js.Any] = js.constructorTag[A] // error
4961
| ^
5062
| A is not a class type
63+
|
64+
| longer explanation available when compiling with `-explain`
5165
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:26:69 ----------------------------
5266
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorTag[A] // error
5367
| ^
5468
| A is not a class type
69+
|
70+
| longer explanation available when compiling with `-explain`

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`

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)