D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7262 - 'used before set' error with no line number
Summary: 'used before set' error with no line number
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 major
Assignee: No Owner
URL:
Keywords: diagnostic, patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-01-09 18:03 UTC by bearophile_hugs
Modified: 2012-02-17 03:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-01-09 18:03:52 UTC
import std.algorithm: map;
import std.typecons: tuple;
int foo() {
    return 0;
}
void main() {
    auto bars = map!(n => tuple(foo(), n))([10]);
    auto spam = bars.front[1];
}


Compiling with:
dmd -O test.d


DMD 2.058head gives:

Error: variable __tup818 used before set

Note the lack of error line number.
Comment 1 Kenji Hara 2012-01-09 19:09:39 UTC
It is tuple + indexing + optimization bug.

Workaround:

void main() {
   auto bars = map!(n => tuple(foo(), n))([10]);
   auto spam_tup = bars.front;//[1];   // save whole tuple temporarily
   auto spam = spam_tup[1];            // get an element of tuple
}

It will be fixed by merging:
https://github.com/D-Programming-Language/dmd/pull/609
Comment 2 yebblies 2012-02-17 03:41:15 UTC
Works for me, presumably fixed by the fix to issue 4940

https://github.com/D-Programming-Language/dmd/commit/d6ede2edc28c94b6b3372eb1301cf300b0860eb6