Skip to content

Comments

fix Issue 17494 - Do not execute scope(...) if an Error exception has…#6896

Open
WalterBright wants to merge 1 commit intodlang:masterfrom
WalterBright:fix17494
Open

fix Issue 17494 - Do not execute scope(...) if an Error exception has…#6896
WalterBright wants to merge 1 commit intodlang:masterfrom
WalterBright:fix17494

Conversation

@WalterBright
Copy link
Member

@WalterBright WalterBright commented Jun 12, 2017

… been thrown

fix 17494

This is an enhancement, see https://issues.dlang.org/show_bug.cgi?id=17494

It's also a regression fix.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 12, 2017

Thanks for your pull request, @WalterBright!

Bugzilla references

Auto-close Bugzilla Severity Description
17494 enhancement Do not execute scope(...) if an Error exception has been thrown

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#6896"

@WalterBright WalterBright added the Severity:Regression PRs that fix regressions label Jun 12, 2017
@CyberShadow
Copy link
Member

fix 17493

This should be in the commit message as well, so it's picked up by @dlang-bot.

@WalterBright
Copy link
Member Author

This should be in the commit message as well, so it's picked up by @dlang-bot.

I don't know what dlang-bot looks for, everything I try fails. I tried "fix 17493" and "fix issue 17493", to no avail.

@CyberShadow
Copy link
Member

I don't know what dlang-bot looks for, everything I try fails. I tried "fix 17493" and "fix issue 17493", to no avail.

Are you editing the commit message (when creating the git commit on your computer), or the pull request description (in your web browser)? We're talking about the former.

@wilzbach
Copy link
Contributor

Are you editing the commit message (when creating the git commit on your computer), or the pull request description (in your web browser)? We're talking about the former.

I think I mention the link to the explanation almost daily ;-)
https://github.com/dlang-bots/dlang-bot

And in dubito, try it online

Of course you can also execute the D function yourself:

import std.algorithm, std.conv, std.range, std.string;
import std.format : format;

auto matchIssueRefs(string message)
{
    import std.regex;

    static auto matchToRefs(M)(M m)
    {
        enum splitRE = regex(`[^\d]+`); // ctRegex throws a weird error in unittest compilation
        auto closed = !m.captures[1].empty;
        return m.captures[5].stripRight.splitter(splitRE)
            .filter!(id => !id.empty) // see #6
            .map!(id => IssueRef(id.to!int, closed));
    }

    // see https://github.com/github/github-services/blob/2e886f407696261bd5adfc99b16d36d5e7b50241/lib/services/bugzilla.rb#L155
    enum issueRE = ctRegex!(`((close|fix|address)e?(s|d)? )?(ticket|bug|tracker item|issue)s?:? *([\d ,\+&#and]+)`, "i");
    return message.matchAll(issueRE).map!matchToRefs.joiner;
}

struct IssueRef { int id; bool fixed; }

void main()
{
   import std.stdio;
   matchIssueRefs("fix Issue 17494 17493 - Do not execute scope(...) if an Error ").writeln;
}

@andralex
Copy link
Member

andralex commented Jun 12, 2017

Cool! A promise made by the spec finally fulfilled. This will allow smaller and faster functions for most cases.

We'll need a changelog entry as well.

@WalterBright
Copy link
Member Author

We're talking about the former.

It used to work by looking at the github comments.

@wilzbach
Copy link
Contributor

Hmm #6816 also broke D-YAML, but this bugfix PR doesn't seem to fix the regression observed in D-YAML.

(working on a reduction)

@MartinNowak
Copy link
Member

It used to work by looking at the github comments.

It never did that, we want our information in git to be available for tooling, not locked into a proprietary platform.

@MartinNowak
Copy link
Member

MartinNowak commented Jun 17, 2017

We're about to release 2.075.0 soon, so let's not try to counter a risky change with yet another one (changing all scope (failure) catch handlers from Throwable to Exception).
Given the amount of fallout, I'd rather revert #6816 for now and revisit it for the next major version (2.076 if we don't yet change the version scheme).

@WalterBright
Copy link
Member Author

I agree it's a risky change.

@MartinNowak
Copy link
Member

Apparently hangs some test in dmd's test suite.

@andralex
Copy link
Member

@WalterBright I'll approve pending the unittester, I suppose this needs a bit of work.

@braddr
Copy link
Member

braddr commented Oct 16, 2017

removing the auto-merge flag because the tests don't pass and in fact are stalling resulting in abnormally long builds that must hit timeouts to end.

@JohanEngelen
Copy link
Contributor

If the agreement is that no unwinding should happen if an Error is thrown, then the standard exception handling mechanism should not be used: by throwing an exception, (some) unwinding will always happen...

@ghost
Copy link

ghost commented Sep 5, 2020

What is the status of the issue ? It's marked closed. Can this PR be as well ?
Also note that the test case has never failed to compile.

rdmd playground.d

All versions: Success and no output

@MoonlightSentinel
Copy link
Contributor

MoonlightSentinel commented Sep 5, 2020

What is the status of the issue ? It's marked closed. Can this PR be as well ?

Commented on the issue, scope(exit) is still executed for Errors.

Also note that the test case has never failed to compile.

Not for official releases - the changes from -preview=dtorfields were initiallly enabled by default but hidden as a preview because of the code breakage IIRC.


A small test case;

// nothrow: // Uncomment this to make the test pass

void main()
{
    bool caught;

    try
        foo();
    catch (Error)
        caught = true;

    assert(caught);
    assert(counter == 0);
}

__gshared int counter = 0;

void foo()
{
    scope (exit) counter++;
    throwError();
}

void throwError()
{
    throw new Error("");
}

@12345swordy
Copy link
Contributor

@WalterBright tests have failed.

@WalterBright
Copy link
Member Author

The tests all fail because the test suite hangs and times out. There's no clue which test hung.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.