Skip to content

Issue 1800 - typing error problem with using macro, switch and type parameter - haxe #1800

Closed
@issuesbot

Description

@issuesbot

[Google Issue #1800 : https://code.google.com/p/haxe/issues/detail?id=1800]
by heinz.ho...@googlemail.com, at 09/05/2013, 23:00:14
try to compile the following code. It fails with

Bug.hx:22: characters 23-30 : Unknown<0> should be {+ get : Void -> Unknown<0> }
Bug.hx:22: characters 23-30 : For function argument 'v'
Bug.hx:22: characters 4-8 : Void should be haxe.ds.Option<{+ get : Void -> Unknown<0> }>


package ;

import haxe.ds.Option;

using Bug.Helper;

class Helper {
    macro public static function get <T>(e:haxe.macro.Expr.ExprOf<T>):haxe.macro.Expr.ExprOf<T> return e;
    }
class Bug {
    static function test <T>(a:Array<T>) {
        var v = None; // fails
        // var v:Option<T> = None; // fails also
        for (e in a) {
            v = switch (v) {
                case Some(x): Some(x.get());
                case None: Some(e);
                }
            }
        }
    static function main () {
        test([1,2]);
        }
    }

without type parameter it only fails when v is not explicitly typed:

static function test (a:Array<Int>) {
    // var v = None // fails
    var v:Option<T> = None; // works
    for (e in a) {
        v = switch (v) {
            case Some(x): Some(x.get());
            case None: Some(e);
            }
        }
    }

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions