Skip to content

Reduce usage of scope that relied on issue 20150#254

Merged
atilaneves merged 1 commit intoatilaneves:masterfrom
dkorpel:fix-pure-scope
Aug 4, 2021
Merged

Reduce usage of scope that relied on issue 20150#254
atilaneves merged 1 commit intoatilaneves:masterfrom
dkorpel:fix-pure-scope

Conversation

@dkorpel
Copy link
Contributor

@dkorpel dkorpel commented Jul 11, 2021

Needed to pass buildkite on dlang/dmd#12010

Sometimes scope had to be added (in does not mean scope yet), most of the time it had to be removed.
It could still be inferred since they are template functions, but it's very fragile: a single call to a non-scope toString() will make everything above it fail to be scope (and correctly so). This could be improved, but for now I'm focussed on making the accepts-invalid go away.

Issue 20150 means that parameters on pure functions are assumed `scope` even
when they could be returned or assigned to an object passed through a different
parameter.
* Verify that two values are the same.
* Throws: UnitTestException on failure
*/
void shouldEqual(V, E)(scope auto ref V value, scope auto ref E expected, string file = __FILE__, size_t line = __LINE__)
Copy link

@nordlow nordlow Jul 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what's wrong with having scope here. Is it because value and expected may referenced from inside the the UnitTestException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could still be inferred, but this functions calls formatValueInItsOwnLine on value which calls convertToString which might call value.toString which might not be scope.



// Formats output in different lines
private string[] formatValueInItsOwnLine(T)(in string prefix, scope auto ref T value) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in doesn't imply scope without -preview=in. I didn't want to add -preview=in to unit-threaded because that's an unapproved feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: attribute scope cannot be applied with in, use -preview=in instead

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove in?

I asked the same question. See above.

@dkorpel
Copy link
Contributor Author

dkorpel commented Jul 29, 2021

@atilaneves Can you approve or request changes? This is blocking a fix for a critical dip1000 issue in dmd.

@atilaneves atilaneves merged commit a19a7cd into atilaneves:master Aug 4, 2021
@dkorpel dkorpel deleted the fix-pure-scope branch August 4, 2021 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants