D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7644 - [tdpl] receive( (OwnerTerminated) {} ); fails to compile
Summary: [tdpl] receive( (OwnerTerminated) {} ); fails to compile
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-04 04:51 UTC by Peter Alexander
Modified: 2012-03-05 11:15 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 Peter Alexander 2012-03-04 04:51:48 UTC
The code snippet on this page no longer compiles in 2.059

http://www.informit.com/articles/article.aspx?p=1609144&seqNum=8

Minimal example:
--------------------------------
void foo() {
    import std.concurrency;
    receive( (OwnerTerminated) { } );
}
--------------------------------

std/concurrency.d(529): Error: cannot have parameter of type void
std/concurrency.d(529): Error: variable std.concurrency.receive!(void).receive._param_0 voids have no value


The problem appears to be with lambdas with unnamed user-defined parameters:

--------------------------------
class Foo {}
auto a = (Foo) {}; // error
auto b = (Foo f) {}; // ok
--------------------------------

If this is intentional, it wasn't mentioned as a breaking change in the 2.059 changelog.
Comment 1 Walter Bright 2012-03-04 10:57:36 UTC
With:

  class Foo {}
  auto a = (Foo) {}; // error

I get with 2.058 and 2.059:

  Error: cannot infer type from ambiguous function literal __lambda2

That's different from what you say you're getting. It's also correct, as the type of parameter Foo cannot be inferred.
Comment 2 Peter Alexander 2012-03-04 14:14:19 UTC
(In reply to comment #1)
> With:
> 
>   class Foo {}
>   auto a = (Foo) {}; // error
> 
> I get with 2.058 and 2.059:
> 
>   Error: cannot infer type from ambiguous function literal __lambda2
> 
> That's different from what you say you're getting. It's also correct, as the
> type of parameter Foo cannot be inferred.

That's the same as what I get. The error message in the post relates to the OwnerTerminated code snippet above it.

I don't understand what you mean with the type inference for the Foo parameter. The type is Foo.

Is this an errata for TDPL?
Comment 3 Don 2012-03-05 04:56:28 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > With:
> > 
> >   class Foo {}
> >   auto a = (Foo) {}; // error
> > 
> > I get with 2.058 and 2.059:
> > 
> >   Error: cannot infer type from ambiguous function literal __lambda2
> > 
> > That's different from what you say you're getting. It's also correct, as the
> > type of parameter Foo cannot be inferred.
> 
> That's the same as what I get. The error message in the post relates to the
> OwnerTerminated code snippet above it.
> 
> I don't understand what you mean with the type inference for the Foo parameter.
> The type is Foo.

The change in 2.058 was that given:
auto a = (x) { ... };
x is a parameter, of type to be inferred.
Previously, it was assumed to be a type.

> Is this an errata for TDPL?

I believe so. Should be rewritten to something like:

void foo() {
    import std.concurrency;
    receive( (OwnerTerminated  x) { } );
}
Comment 4 Walter Bright 2012-03-05 11:15:00 UTC
Since this is now the way the language is supposed to work, I'm going to close this as not a bug.