File tree 3 files changed +14
-11
lines changed
3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -6900,8 +6900,8 @@ extern (C++) final class Parameter : ASTNode
6900
6900
* Params:
6901
6901
* returnByRef = true if the function returns by ref
6902
6902
* p = Parameter to compare with
6903
- * previewIn = Whether `-previewIn ` is being used, and thus if
6904
- * `in` means `scope`.
6903
+ * previewIn = Whether `-preview=in ` is being used, and thus if
6904
+ * `in` means `scope [ref] `.
6905
6905
*
6906
6906
* Returns:
6907
6907
* true = `this` can be used in place of `p`
@@ -6921,8 +6921,8 @@ extern (C++) final class Parameter : ASTNode
6921
6921
otherSTC |= STC .scope_;
6922
6922
}
6923
6923
6924
- enum stc = STC .ref_ | STC .out_ | STC .lazy_;
6925
- if ((thisSTC & stc ) != (otherSTC & stc ))
6924
+ const mask = STC .ref_ | STC .out_ | STC .lazy_ | (previewIn ? STC .in_ : 0 ) ;
6925
+ if ((thisSTC & mask ) != (otherSTC & mask ))
6926
6926
return false ;
6927
6927
return isCovariantScope (returnByRef, thisSTC, otherSTC);
6928
6928
}
Original file line number Diff line number Diff line change @@ -558,7 +558,7 @@ class Parameter : public ASTNode
558
558
static size_t dim (Parameters *parameters);
559
559
static Parameter *getNth (Parameters *parameters, d_size_t nth);
560
560
const char *toChars () const ;
561
- bool isCovariant (bool returnByRef, const Parameter *p) const ;
561
+ bool isCovariant (bool returnByRef, const Parameter *p, bool previewIn ) const ;
562
562
};
563
563
564
564
struct ParameterList
Original file line number Diff line number Diff line change @@ -24,14 +24,17 @@ struct FooBar
24
24
string toString () const
25
25
{
26
26
string result;
27
+ // Type is const
28
+ this .toString((in char [] buf) {
29
+ static assert (is (typeof (buf) == const (char [])));
30
+ result ~= buf;
31
+ });
27
32
// Type inference works
28
- this .toString((buf) { result ~= buf; });
29
- // Specifying the STC too
30
33
this .toString((in buf) { result ~= buf; });
31
- // Some covariance
32
- this .toString((const scope buf) { result ~= buf; });
33
- this .toString((scope const ( char )[] buf) { result ~= buf; });
34
- this .toString((scope const ( char []) buf) { result ~= buf; });
34
+ // No covariance without explicit `in`
35
+ static assert ( ! __traits(compiles, { this .toString((buf) { result ~= buf; }); }) );
36
+ static assert ( ! __traits(compiles, { this .toString((const scope buf) { result ~= buf; }); }) );
37
+ static assert ( ! __traits(compiles, { this .toString((const scope ref buf) { result ~= buf; }); }) );
35
38
return result;
36
39
}
37
40
You can’t perform that action at this time.
0 commit comments