Skip to content

Commit 6f4275c

Browse files
authored
Start work on improving subtype error messages (#7404)
* structure for improving subtype errors * variant configuration errors * different constructor counts * format * update test output * different type kinds * missing fn * record fields mismatch * more hints about what types we are looking at * Revert "more hints about what types we are looking at" This reverts commit 55476b9. * refactor * format * cleanup * expand comments tracking work left to do * add comments * changelog * change fn name * pr comments
1 parent c8e2639 commit 6f4275c

File tree

39 files changed

+957
-133
lines changed

39 files changed

+957
-133
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- Show in error messages when coercion can be used to fix a type mismatch. https://github.com/rescript-lang/rescript/pull/7505
3434
- Remove deprecated pipe last (`|>`) syntax. https://github.com/rescript-lang/rescript/pull/7512
3535
- Improve error message for pipe (`->`) syntax. https://github.com/rescript-lang/rescript/pull/7520
36+
- Improve a few error messages around various subtyping issues. https://github.com/rescript-lang/rescript/pull/7404
3637

3738
# 12.0.0-alpha.13
3839

compiler/ml/ast_untagged_variants.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ type block_type =
7171
| ObjectType
7272
| UnknownType
7373

74+
let block_type_to_user_visible_string = function
75+
| IntType -> "int"
76+
| StringType -> "string"
77+
| FloatType -> "float"
78+
| BigintType -> "bigint"
79+
| BooleanType -> "bool"
80+
| InstanceType i -> Instance.to_string i
81+
| FunctionType -> "function"
82+
| ObjectType -> "object"
83+
| UnknownType -> "unknown"
84+
7485
(*
7586
Type of the runtime representation of a tag.
7687
Can be a literal (case with no payload), or a block (case with payload).
@@ -89,6 +100,16 @@ type tag = {name: string; tag_type: tag_type option}
89100
type block = {tag: tag; tag_name: string option; block_type: block_type option}
90101
type switch_names = {consts: tag array; blocks: block array}
91102

103+
let tag_type_to_user_visible_string = function
104+
| String _ -> "string"
105+
| Int _ -> "int"
106+
| Float _ -> "float"
107+
| BigInt _ -> "bigint"
108+
| Bool _ -> "bool"
109+
| Null -> "null"
110+
| Undefined -> "undefined"
111+
| Untagged block_type -> block_type_to_user_visible_string block_type
112+
92113
let untagged = "unboxed"
93114

94115
let block_type_can_be_undefined = function

0 commit comments

Comments
 (0)