digitalmars.D.bugs - [Issue 799] New: Array literal with covariant types
- d-bugmail puremagic.com (25/25) Jan 06 2007 http://d.puremagic.com/issues/show_bug.cgi?id=799
- d-bugmail puremagic.com (17/17) Jan 06 2007 http://d.puremagic.com/issues/show_bug.cgi?id=799
- d-bugmail puremagic.com (11/11) Feb 02 2007 http://d.puremagic.com/issues/show_bug.cgi?id=799
http://d.puremagic.com/issues/show_bug.cgi?id=799 Summary: Array literal with covariant types Product: D Version: 1.00 Platform: Other OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: aarti interia.pl class BaseClass {} class Class1 : BaseClass {} class Class2 : BaseClass {} BaseClass[] array; void main() { array=[new BaseClass, new Class1, new Class2]; //Below gives compile time error //Error: cannot implicitly convert expression (new Class2) of type //array_literal_with_covariants.Class2 to //array_literal_with_covariants.Class1 array=[new Class1, new Class2]; } --
Jan 06 2007
http://d.puremagic.com/issues/show_bug.cgi?id=799 fvbommel wxs.nl changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Keywords| |spec OS/Version|Linux |All Platform|Other |All ------- Comment #1 from fvbommel wxs.nl 2007-01-06 10:43 ------- Array literals have type T[], where T is the type of the first element (except when that's a static array, then it's the dynamic version IIRC). Try this: array=[cast(BaseClass)new Class1, new Class2]; That should work. It'd be nice if the original code worked though, so I'm changing this to an enhancement request. --
Jan 06 2007
http://d.puremagic.com/issues/show_bug.cgi?id=799 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |WONTFIX ------- Comment #2 from bugzilla digitalmars.com 2007-02-03 01:05 ------- The request is to find the "greatest common denominator" to use as the type for an array literal. While this is possible to implement, I feel it is much more understandable to just take the type of the first element. --
Feb 02 2007