D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7263 - Tuple indexing/slicing + -O switch causes "used before set" error
Summary: Tuple indexing/slicing + -O switch causes "used before set" error
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-01-09 19:24 UTC by Kenji Hara
Modified: 2012-02-17 03:42 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 Kenji Hara 2012-01-09 19:24:23 UTC
Sample code:
----
template TypeTuple(T...){ alias T TypeTuple; }

struct tuple
{
    TypeTuple!(int, int) field;
    alias field this;
}

auto front(T)(ref T arr){ return arr[0]; }

void main() {
    auto bars = [tuple(0, 0), tuple(1, 1)];
    auto spam = bars.front[1..2];   //
}

Output:
----
Error: variable __tup3 used before set
Comment 2 Kenji Hara 2012-01-12 00:59:46 UTC
Tuple indexing has same problem.

template TypeTuple(T...){ alias T TypeTuple; }

struct tuple
{
    TypeTuple!(int, int) field;
    alias field this;
}

auto front(T)(ref T arr){ return arr[0]; }

void main() {
    auto bars = [tuple(0, 0), tuple(1, 1)];
    auto spam1 = bars.front[1];      // indexing
    auto spam2 = bars.front[1..2];   // slicing
}
Comment 3 yebblies 2012-02-17 03:42:39 UTC
Works for me, presumably fixed by the fix to issue 4940

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