Skip to content

Conversation

thewilsonator
Copy link
Contributor

@thewilsonator thewilsonator commented Sep 11, 2022

This fixes the issue, I'm not sure if the correct thing to do is to make DMD not emit bogus ASTs to begin with.

fixes #4130

@@ -307,7 +307,8 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) {
IF_LOG Logger::println("Current function is %s", ctxfd->toChars());
if (fromParent) {
ctxfd = getParentFunc(ctxfd);
assert(ctxfd && "Context from outer function, but no outer function?");
if (!ctxfd)
ctxfd = irFunc.decl;
Copy link
Member

Choose a reason for hiding this comment

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

add log output about this strange case?

Copy link
Member

Choose a reason for hiding this comment

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

does this actually produce correct code now?

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 doesn't crash, which is what it did before. As for the correctness of the code,I'm not really sure, but I don't know what its supposed to do other than iterate through the linked list of classes. @ZILtoid1991 could you provide a reduced test case of this code in action?

Choose a reason for hiding this comment

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

class DOMImplementation {
class Attr  {  Attr  _nextAttr; }
class Map  {
    Attr firstAttr;
    auto opSlice()
    {
         struct Range
         {
             Attr currentAttr;

             auto front() { return currentAttr; }
             void popFront() { currentAttr = currentAttr._nextAttr; }
             bool empty() { return currentAttr is null; }
        }
       return Range(firstAttr);
   }
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Thx, somewhat further reduced:

class Outer {
    class Inner {
        auto opSlice() {
            struct Range {
                void foo() {}
            }
            return Range();
        }
    }
}

2 outer aggregates are apparently required, and both need to be classes (works with any one of them being a struct).

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't crash, which is what it did before. As for the correctness of the code,I'm not really sure, but I don't know what its supposed to do other than iterate through the linked list of classes.

If unsure about the correct behavior, then better to exit gracefully instead of silently continuing.

@thewilsonator thewilsonator merged commit f4bbcdd into ldc-developers:master Sep 16, 2022
@thewilsonator thewilsonator deleted the issue-4130 branch September 16, 2022 03:01
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.

My code crashes the LDC compiler, while compiles just fine for DMD
4 participants