Use the 'most derived type' to determine the type of raw array literals #10

Closed
ghost opened this Issue Apr 19, 2010 · 6 comments

Comments

Projects
None yet
4 participants
@ghost

ghost commented Apr 19, 2010

Currently the documentation states that the type for the raw array literal is derived from the first element in the literal:
http://docs.ooc-lang.org/language/syntax.html#raw-arrays

A better rule will be to use the 'most derived type' - the type to which all the other types can be implicitly converted to. In no such type exists in the literal, it probably should be an error.

For example: [1, 2, 3.0] should be a raw array of Double (assuming that the "1" and "2" literals are 32-bit integers).
Similarly, having classes "Foo" and "Bar extends Foo", [Foo new(), Bar new()] should be a raw array of Foo.

Member

nddrylliog commented May 11, 2010

Maybe the Type getScore(Type) function could be used for such a purpose. Try type1 getScore(type2) vs type2 getScore(type1), whoever wins gets to be the array's innerType. If the score is negative (except -1, which means something has to be resolved first), throw an error that there are incompatible types in the array literal.

solson commented Jul 31, 2010

This way of handling it makes the most sense, +1

Collaborator

duckinator commented Aug 31, 2011

EPICBUMP
(aka a bump after a year and a month, while poking around bugs at 2am because I thought I found a problem but did not)

WITH THAT, I GO TO BED. Hopefully.

Collaborator

duckinator commented Nov 28, 2011

Ok, I may take a whack at this sometime. No promises, though. :P

duckinator referenced this issue Nov 28, 2011

Closed

misc cleanup #318

Collaborator

duckinator commented Feb 16, 2013

BUMP. Hi @shamanas.

@shamanas shamanas added a commit that referenced this issue Feb 20, 2013

@shamanas shamanas Merge pull request #610 from shamanas/master
Use findCommonRoot to infer the type of an array literal. Closes the oldest issue standing, #10
536f51c
Collaborator

shamanas commented Feb 20, 2013

Closed by 536f51c :D

shamanas closed this Feb 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment