D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15083 - declaring a variable, cannot access frame pointer
Summary: declaring a variable, cannot access frame pointer
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-18 11:09 UTC by John Colvin
Modified: 2022-10-13 05:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description John Colvin 2015-09-18 11:09:31 UTC
This uses phobos, but I'm pretty sure typeof should work here so it's a dmd bug.

import std.file;

void file_test(string path, string filetype, string term){
	typeof(dirEntries(path, filetype, SpanMode.depth)) files;
}

Error: cannot access frame pointer of std.file.dirEntries.FilterResult!(f, DirIterator).FilterResult
Comment 1 Marc Schütz 2015-09-18 13:11:09 UTC
(In reply to John Colvin from comment #0)
> This uses phobos, but I'm pretty sure typeof should work here so it's a dmd
> bug.

typeof itself _does_ work, this compiles fine:

pragma(msg, typeof(dirEntries(path, filetype, SpanMode.depth)));
// prints: FilterResult!(f, DirIterator)

But FilteResult is evidently a Voldemort type, and you can't declare a variable of this type. So I believe this is not a bug.
Comment 2 John Colvin 2015-09-18 13:36:18 UTC
(In reply to Marc Schütz from comment #1)
> (In reply to John Colvin from comment #0)
> > This uses phobos, but I'm pretty sure typeof should work here so it's a dmd
> > bug.
> 
> typeof itself _does_ work, this compiles fine:
> 
> pragma(msg, typeof(dirEntries(path, filetype, SpanMode.depth)));
> // prints: FilterResult!(f, DirIterator)

good point

> But FilteResult is evidently a Voldemort type, and you can't declare a
> variable of this type. So I believe this is not a bug.

You can definitely declare variables with Voldemort types.

e.g.
auto foo(){ struct S{} return S(); }
void bar(){ typeof(foo()) a; }

is fine.


The problem here is to do with the initialiser.

	typeof(dirEntries(path, filetype, SpanMode.depth)) files = void;

doesn't cause any problems.
Comment 3 Marc Schütz 2015-09-18 15:30:41 UTC
(In reply to John Colvin from comment #2)
> You can definitely declare variables with Voldemort types.
> 
> e.g.
> auto foo(){ struct S{} return S(); }
> void bar(){ typeof(foo()) a; }
> 
> is fine.
> 

That's not a "real" Voldemort type with a closure; try this instead:

auto foo(){
    int x;
    struct S {
        int baz() { return x; }
    }
    return S();
}
void bar(){ typeof(foo()) a; } // Error: cannot access frame pointer of xx.foo.S

> 
> The problem here is to do with the initialiser.
> 
> 	typeof(dirEntries(path, filetype, SpanMode.depth)) files = void;
> 
> doesn't cause any problems.

This could either be an oversight (= bug), or it could be intentional. I suspect the latter, because it allows to actually declare a Voldemort variable that is only initialized later.
Comment 4 John Colvin 2015-09-18 15:53:46 UTC
(In reply to Marc Schütz from comment #3)
> (In reply to John Colvin from comment #2)
> > You can definitely declare variables with Voldemort types.
> > 
> > e.g.
> > auto foo(){ struct S{} return S(); }
> > void bar(){ typeof(foo()) a; }
> > 
> > is fine.
> > 
> 
> That's not a "real" Voldemort type with a closure; try this instead:
> 
> auto foo(){
>     int x;
>     struct S {
>         int baz() { return x; }
>     }
>     return S();
> }
> void bar(){ typeof(foo()) a; } // Error: cannot access frame pointer of
> xx.foo.S

OK, I see what you mean.

> > 
> > The problem here is to do with the initialiser.
> > 
> > 	typeof(dirEntries(path, filetype, SpanMode.depth)) files = void;
> > 
> > doesn't cause any problems.
> 
> This could either be an oversight (= bug), or it could be intentional. I
> suspect the latter, because it allows to actually declare a Voldemort
> variable that is only initialized later.

Yes, I think it probably is intentional, or at least not a problem that it's allowed.
Comment 5 RazvanN 2022-10-13 05:18:41 UTC
According to Marc Schutz's comments this is not a bug.