Hi, Manfred,

DistArray is a generic type.  Thus, you always have to specify the
appropriate type arguments when referring to an instance of that type
(like in the formals for printDistArray()).

All generic types in X10 are invariant.  So, a DistArray[Int{c}]
cannot be assigned to a variable (or passed into a formal) of type
DistArray[Int] (the constraint makes it a different type).  Because
you did not specify it explicitly, the type of the elements in the
array is actually inferred from the initializer argument of
DistArray.make() (which is a literal "0").

To fix this, you can do one of three things: (a) force the element
type when constructing the array, e.g.,
DistArray.make[Int](distribution, 0), (b) make the formal type of
printDistArray() match the inferred type of the argument, i.e.,
printDistArray(distArray:DistArray[Int{self==0}]), or (c) make
printDistArray generic and let the system infer the type, e.g., def
printDistArray[U](distArray: DistArray[U]) { ... }.

Hope this helps,
        Igor

2011/6/20 Kröhnert, Manfred <manfred.kroehn...@kit.edu>:
> Hello all,
>
> I am using the current X10 v2.2 release on OS X 10.6.7 with the C++ backend 
> and it gives me trouble with the following code:
>
> -------------------------------------------------
> import x10.array.DistArray;
>
> public class Test {
>    public static def main(args: Array[String]) {
>        val region = 0 .. 79;
>
>        val distribution = Dist.makeBlock(region);
>        val array = DistArray.make(distribution, 0);
>        printDistArray(array);
>    }
>
>    static def printDistArray(distArray: DistArray) : void
>    {
>        Console.OUT.println(distArray);
>    }
> }
> -------------------------------------------------
>
> Compiling it produces the following error:
>
> Test.x10:9: No valid method call found for call in given type.
>         Call: printDistArray(x10.array.DistArray[x10.lang.Int])
>         Type: Test
> Test.x10:12: Type is missing parameters.
>         Type: x10.array.DistArray
>         Expected parameters: [T]
> 2 errors.
>
>
> Changing the parameter type to 'distArray: DistArray[Int]' produces this 
> compiler error:
>
> Test.x10:9: Parameter 0 does not have the expected base type.
>         Formal base type: x10.array.DistArray[x10.lang.Int]
>         Actual base type: x10.array.DistArray[x10.lang.Int{self==0, 
> horizontalDist.region.zeroBased==true, horizontalDist.region.rect==true, 
> horizontalDist.region.rank==1, horizontalDist.region!=null, 
> x10.array.PlaceGroup.WORLD!=null, region.zeroBased==true, region.min==0, 
> region.max==79, region!=null}]{self==h_sum, h_sum.dist==horizontalDist, 
> h_sum!=null, horizontalDist.region.zeroBased==true, 
> horizontalDist.region.rect==true, horizontalDist.region.rank==1, 
> horizontalDist.region!=null, x10.array.PlaceGroup.WORLD!=null, 
> region.zeroBased==true, region.min==0, region.max==79, region!=null}
>         (method static Test.printDistArray(arg93: 
> x10.array.DistArray[x10.lang.Int]))
> 1 error.
>
>
> And my last try was to use the type Any like this 'distArray: DistArray[Any]' 
> which also results in an error:
>
> Test.x10:9: No valid method call found for call in given type.
>         Call: printDistArray(x10.array.DistArray[x10.lang.Int])
>         Type: Test
> 1 error.
>
> Can anybody give me a hint on how to achieve this correctly or is this a bug 
> in X10 somehow?
> I would have expected the code to work as it is given in the first place.
>
> Best,
> Manfred

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to