Skip to content

Commit

Permalink
Backport "Update phrasing for NotClassType explain error message" to …
Browse files Browse the repository at this point in the history
…LTS (#20923)

Backports #19635 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur committed Jul 2, 2024
2 parents 71a6391 + 403262c commit 424da1c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,11 @@ extends SyntaxMsg(TargetNameOnTopLevelClassID):
class NotClassType(tp: Type)(using Context)
extends TypeMsg(NotClassTypeID), ShowMatchTrace(tp):
def msg(using Context) = i"$tp is not a class type"
def explain(using Context) = ""
def explain(using Context) =
i"""A class type includes classes and traits in a specific order. Defining a class, even an anonymous class,
|requires specifying a linearization order for the traits it extends. For example, `A & B` is not a class type
|because it doesn't specify which trait takes precedence, A or B. For more information about class types, please see the Scala Language Specification.
|Class types also can't have refinements."""

class NotConstant(suffix: String, tp: Type)(using Context)
extends TypeMsg(NotConstantID), ShowMatchTrace(tp):
Expand Down
5 changes: 5 additions & 0 deletions docs/_docs/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ checkfiles with the test outputs.
$ sbt
> testCompilation --update-checkfiles
```
Or for ScalaJS
```bash
$ sbt
> sjsCompilerTests/testOnly -- -Ddotty.tests.updateCheckfiles=TRUE
```

Use `--help` to see all the options
```bash
Expand Down
16 changes: 16 additions & 0 deletions tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
14 | val b = js.constructorOf[NativeJSObject.type] // error
| ^^^^^^^^^^^^^^^^^^^
| NativeJSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:16:27 -----------------------------
16 | val c = js.constructorOf[NativeJSClass with NativeJSTrait] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| NativeJSClass & NativeJSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:17:27 -----------------------------
17 | val d = js.constructorOf[NativeJSClass { def bar: Int }] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| NativeJSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:19:27 -----------------------------------------
19 | val e = js.constructorOf[JSTrait] // error
| ^^^^^^^
Expand All @@ -22,19 +28,29 @@
20 | val f = js.constructorOf[JSObject.type] // error
| ^^^^^^^^^^^^^
| JSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:22:27 -----------------------------
22 | val g = js.constructorOf[JSClass with JSTrait] // error
| ^^^^^^^^^^^^^^^^^^^^
| JSClass & JSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:23:27 -----------------------------
23 | val h = js.constructorOf[JSClass { def bar: Int }] // error
| ^^^^^^^^^^^^^^^^^^^^^^^^
| JSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:25:42 -----------------------------
25 | def foo[A <: js.Any] = js.constructorOf[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructorof-error-in-prepjsinterop.scala:26:66 -----------------------------
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorOf[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
16 changes: 16 additions & 0 deletions tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
14 | val b = js.constructorTag[NativeJSObject.type] // error
| ^
| NativeJSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:16:61 ----------------------------
16 | val c = js.constructorTag[NativeJSClass with NativeJSTrait] // error
| ^
| NativeJSClass & NativeJSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:17:59 ----------------------------
17 | val d = js.constructorTag[NativeJSClass { def bar: Int }] // error
| ^
| NativeJSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:19:36 ----------------------------------------
19 | val e = js.constructorTag[JSTrait] // error
| ^
Expand All @@ -22,19 +28,29 @@
20 | val f = js.constructorTag[JSObject.type] // error
| ^
| JSObject.type is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:22:49 ----------------------------
22 | val g = js.constructorTag[JSClass with JSTrait] // error
| ^
| JSClass & JSTrait is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:23:53 ----------------------------
23 | val h = js.constructorTag[JSClass { def bar: Int }] // error
| ^
| JSClass{def bar: Int} is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:25:45 ----------------------------
25 | def foo[A <: js.Any] = js.constructorTag[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg-scalajs/jsconstructortag-error-in-prepjsinterop.scala:26:69 ----------------------------
26 | def bar[A <: js.Any: scala.reflect.ClassTag] = js.constructorTag[A] // error
| ^
| A is not a class type
|
| longer explanation available when compiling with `-explain`
6 changes: 6 additions & 0 deletions tests/neg/classOf.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
6 | def f1[T] = classOf[T] // error
| ^
| T is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/classOf.scala:7:32 ---------------------------------------------------------------------
7 | def f2[T <: String] = classOf[T] // error
| ^
| T is not a class type
|
| where: T is a type in method f2 with bounds <: String
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/classOf.scala:9:18 ---------------------------------------------------------------------
9 | val y = classOf[C { type I = String }] // error
| ^^^^^^^^^^^^^^^^^^^^^
| Test.C{type I = String} is not a class type
|
| longer explanation available when compiling with `-explain`
4 changes: 4 additions & 0 deletions tests/neg/i13808.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^^^^^^^^
| OpaqueTypes.OpaqueType is not a class type
|
| longer explanation available when compiling with `-explain`
-- [E170] Type Error: tests/neg/i13808.scala:13:49 ---------------------------------------------------------------------
13 |case class Boom[A](value: A) derives OpaqueType, Foo // error // error
| ^^^
| FooModule.Foo is not a class type
|
| longer explanation available when compiling with `-explain`

0 comments on commit 424da1c

Please sign in to comment.