You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(compiler): improve clarity of common type error messages
- Enhanced UnificationFailed with 'Type mismatch' prefix
- Clarified reference return errors with advice on using '@' or owned values
- Improved NotAType and NotAmongRegisteredTypes with advice for external types
- Refined wording for better developer experience
"`let` expressions can’t return references. The expression '"++ pretty xobj ++"' has the type"
221
221
++show t
222
222
++" at "
223
223
++ prettyInfoFromXObj xobj
224
-
++"\n\nYou’ll have to copy the return value using `@`."
224
+
++".\n\nYou’ll have to copy the return value using `@` or return an owned value."
225
225
show (GettingReferenceToUnownedValue xobj) =
226
226
"You’re referencing a given-away value `"++ pretty xobj ++"` at "
227
227
++ prettyInfoFromXObj xobj --"' (expression " ++ freshVar i ++ ") at " ++
@@ -236,17 +236,22 @@ instance Show TypeError where
236
236
"You’re using a value `"++ pretty xobj
237
237
++"` that was captured by a function at "
238
238
++ prettyInfoFromXObj xobj
239
-
++"."
239
+
++".\n\nCaptured values can't be moved. You'll have to borrow it using `&` or copy it using `@`."
240
240
show (ArraysCannotContainRefs xobj) =
241
241
"Arrays can’t contain references: `"++ pretty xobj ++"` at "
242
242
++ prettyInfoFromXObj xobj
243
243
++".\n\nYou’ll have to make a copy using `@`."
244
-
show (MainCanOnlyReturnUnitOrInt_ t) =
245
-
"The main function can only return an `Int` or a unit type (`()`), but it got `"
244
+
show (MainCanOnlyReturnUnitOrIntxobj t) =
245
+
"The main function can only return an `Int` or a unit type `()`, but it got `"
246
246
++show t
247
-
++"`."
248
-
show (MainCannotHaveArguments _ c) =
249
-
"The main function may not receive arguments, but it got "++show c ++"."
247
+
++"` at "
248
+
++ prettyInfoFromXObj xobj
249
+
++"."
250
+
show (MainCannotHaveArguments xobj c) =
251
+
"The main function may not receive arguments, but it got "++show c
252
+
++" at "
253
+
++ prettyInfoFromXObj xobj
254
+
++"."
250
255
show (CannotConcretize xobj) =
251
256
"I’m unable to concretize the expression '"++ pretty xobj ++"' at "
252
257
++ prettyInfoFromXObj xobj
@@ -259,7 +264,7 @@ instance Show TypeError where
259
264
show (NotAType xobj) =
260
265
"I don’t understand the type '"++ pretty xobj ++"' at "
261
266
++ prettyInfoFromXObj xobj
262
-
++"\n\nIs it defined?"
267
+
++".\n\nIs it defined? If it's an external type, make sure it's registered using `register-type`."
263
268
show (CannotSet xobj) =
264
269
"I can’t `set!` the expression `"++ pretty xobj ++"` at "
265
270
++ prettyInfoFromXObj xobj
@@ -303,7 +308,7 @@ instance Show TypeError where
303
308
show (NotAmongRegisteredTypes t xobj) =
304
309
"I can’t find a definition for the type `"++show t ++"` at "
305
310
++ prettyInfoFromXObj xobj
306
-
++".\n\nWas it registered?"
311
+
++".\n\nIs it defined? If it's an external type, make sure it's registered using `register-type`."
307
312
show (UnevenMembers xobjs) =
308
313
"The number of members and types is uneven: `"
309
314
++ joinWithComma (map pretty xobjs)
@@ -320,11 +325,15 @@ instance Show TypeError where
320
325
++ prettyInfoFromXObj (head xobjs)
321
326
++". \n\n Binding names must be symbols."
322
327
show (DuplicateBinding xobj) =
323
-
"I encountered a duplicate binding `"++ pretty xobj ++"` inside the `let` at "++ prettyInfoFromXObj xobj ++"."
328
+
"I encountered a duplicate binding `"++ pretty xobj ++"` inside the `let` at "
329
+
++ prettyInfoFromXObj xobj
330
+
++".\n\nEach name in a `let` must be unique."
324
331
show (DefinitionsMustBeAtToplevel xobj) =
325
332
"I encountered a definition that was not at top level: `"++ pretty xobj ++"`"
326
333
show (UsingDeadReference xobj dependsOn) =
327
-
"The reference '"++ pretty xobj ++"' (depending on the variable '"++ dependsOn ++"') isn't alive at "++ prettyInfoFromXObj xobj ++"."
334
+
"The reference '"++ pretty xobj ++"' is no longer valid because the value it depends on (`"++ dependsOn ++"`) has been moved or deleted at "
335
+
++ prettyInfoFromXObj xobj
336
+
++"."
328
337
show (UninhabitedConstructor ty xobj got wanted) =
329
338
"Can't use a struct or sumtype constructor without arguments as a member type at "++ prettyInfoFromXObj xobj ++". The type constructor "++show ty ++" expects "++show wanted ++" arguments but got "++show got
0 commit comments