Skip to content

Commit 28f3a62

Browse files
authored
chore: Update general-traits error message (#5191)
Previously, the error message for using `extends` with a non-reference type said that this was a beta feature. It is supported, but requires the CLI option. This PR rewords these error messages. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
1 parent 60a3fea commit 28f3a62

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

Source/DafnyCore/AST/Grammar/ParseErrors.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public enum ErrorId {
137137
p_deprecated_statement_refinement,
138138
p_internal_exception,
139139
p_file_has_no_code,
140-
p_general_traits_beta,
140+
p_general_traits_datatype,
141+
p_general_traits_full,
141142
}
142143

143144
static ParseErrors() {
@@ -153,9 +154,16 @@ static ParseErrors() {
153154
Only modules may be declared abstract.
154155
".TrimStart(), Remove(true));
155156

156-
Add(ErrorId.p_general_traits_beta,
157+
Add(ErrorId.p_general_traits_datatype,
157158
@"
158-
Use of traits as non-reference types is a beta feature. To engage, use /generalTraits:datatype.
159+
A newtype extending a trait is not generally supported. The option --general-traits=full causes
160+
Dafny to allow them in the input, but is not recommended.
161+
".TrimStart(), Remove(true));
162+
163+
Add(ErrorId.p_general_traits_full,
164+
@"
165+
Use of traits as non-reference types is supported, but is not yet the default. Until it becomes the
166+
default, use --general--traits=datatype to enable it.
159167
".TrimStart(), Remove(true));
160168

161169
Add(ErrorId.p_no_ghost_for_by_method,

Source/DafnyCore/Dafny.atg

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,16 @@ ClassDecl<DeclModifierData dmodClass, ModuleDefinition/*!*/ module, out TopLevel
544544
ExtendsClause<. List<Type> parentTraits, out IToken tokenWithTrailingDocString, string requiresNonReferenceTraitsFor .>
545545
= (. Type parentTrait;
546546
.)
547-
"extends" (. if (requiresNonReferenceTraitsFor == "newtype" && theOptions.Get(CommonOptionBag.GeneralTraits) != CommonOptionBag.GeneralTraitsOptions.Full) {
548-
SemErr(ErrorId.p_general_traits_beta, t,
549-
$"{requiresNonReferenceTraitsFor} extending traits is a beta feature; use /generalTraits:full to engage");
550-
} else if (requiresNonReferenceTraitsFor != null && theOptions.Get(CommonOptionBag.GeneralTraits) == CommonOptionBag.GeneralTraitsOptions.Legacy) {
551-
SemErr(ErrorId.p_general_traits_beta, t,
552-
$"{requiresNonReferenceTraitsFor} extending traits is a beta feature; use /generalTraits:datatype to engage");
553-
}
554-
.)
547+
"extends"
548+
(. if (requiresNonReferenceTraitsFor == "newtype" && theOptions.Get(CommonOptionBag.GeneralTraits) != CommonOptionBag.GeneralTraitsOptions.Full) {
549+
SemErr(ErrorId.p_general_traits_full, t,
550+
$"{requiresNonReferenceTraitsFor} extending traits is not fully supported (specifically, compilation of such types is not supported); " +
551+
"to use them for verification only, use --general-traits=full");
552+
} else if (requiresNonReferenceTraitsFor != null && theOptions.Get(CommonOptionBag.GeneralTraits) == CommonOptionBag.GeneralTraitsOptions.Legacy) {
553+
SemErr(ErrorId.p_general_traits_datatype, t,
554+
$"{requiresNonReferenceTraitsFor} extending traits is not yet enabled by default; use --general-traits=datatype to enable it");
555+
}
556+
.)
555557
Type<out parentTrait> (. parentTraits.Add(parentTrait); tokenWithTrailingDocString = t; .)
556558
{"," Type<out parentTrait> (. parentTraits.Add(parentTrait); tokenWithTrailingDocString = t; .) }
557559
.

docs/HowToFAQ/Errors-Parser.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,25 @@ module N refines M { datatype D = ... Y | Z }
248248
There are limitations on refining a datatype, namely that the set of constructors cannot be changed.
249249
It is only allowed to add members to the body of the datatype.
250250

251-
## **Error: datatype extending traits is a beta feature; use /generalTraits:datatype to engage** {#p_general_traits_beta}
251+
## **Error: datatype extending traits is not yet enabled by default; use --general-traits=datatype to enable it** {#p_general_traits_datatype}
252252

253253
```dafny
254254
trait Trait { }
255255
datatype D extends Trait = A | B
256256
```
257257

258-
Use of traits as non-reference types is a beta feature. To engage, use /generalTraits:datatype.
258+
A newtype extending a trait is not generally supported. The option --general-traits=full causes
259+
Dafny to allow them in the input, but is not recommended.
260+
261+
## **Error: newtype extending traits is not fully supported (specifically, compilation of such types is not supported); to use them for verification only, use --general-traits=full** {#p_general_traits_full}
262+
263+
```dafny
264+
trait Trait { }
265+
newtype N extends Trait = int
266+
```
267+
268+
Use of traits as non-reference types is supported, but is not yet the default. Until it becomes the
269+
default, use --general--traits=datatype to enable it.
259270

260271
## **Warning: module-level const declarations are always non-instance, so the 'static' keyword is not allowed here {#p_module_level_const_always_static}
261272

docs/HowToFAQ/Errors-Parser.template

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ module N refines M { datatype D = ... Y | Z }
204204

205205
<!-- INSERT-TEXT -->
206206

207-
## **Error: datatype extending traits is a beta feature; use /generalTraits:datatype to engage** {#p_general_traits_beta}
207+
## **Error: datatype extending traits is not yet enabled by default; use --general-traits=datatype to enable it** {#p_general_traits_datatype}
208208

209209
```dafny
210210
trait Trait { }
@@ -213,6 +213,15 @@ datatype D extends Trait = A | B
213213

214214
<!-- INSERT-TEXT -->
215215

216+
## **Error: newtype extending traits is not fully supported (specifically, compilation of such types is not supported); to use them for verification only, use --general-traits=full** {#p_general_traits_full}
217+
218+
```dafny
219+
trait Trait { }
220+
newtype N extends Trait = int
221+
```
222+
223+
<!-- INSERT-TEXT -->
224+
216225
## **Warning: module-level const declarations are always non-instance, so the 'static' keyword is not allowed here {#p_module_level_const_always_static}
217226

218227
<!-- %check-resolve-warn -->

0 commit comments

Comments
 (0)