=== tests/cases/conformance/functions/functionImplementations.ts ===

// FunctionExpression with no return type annotation and no return statement returns void
var v: void = function () { } ();
>v : Symbol(v, Decl(functionImplementations.ts, 2, 3))

// FunctionExpression f with no return type annotation and directly references f in its body returns any
var a: any = function f() {
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>f : Symbol(f, Decl(functionImplementations.ts, 5, 12))

    return f;
>f : Symbol(f, Decl(functionImplementations.ts, 5, 12))

};
var a: any = function f() {
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>f : Symbol(f, Decl(functionImplementations.ts, 8, 12))

    return f();
>f : Symbol(f, Decl(functionImplementations.ts, 8, 12))

};

// FunctionExpression f with no return type annotation and indirectly references f in its body returns any
var a: any = function f() {
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>f : Symbol(f, Decl(functionImplementations.ts, 13, 12))

    var x = f;
>x : Symbol(x, Decl(functionImplementations.ts, 14, 7))
>f : Symbol(f, Decl(functionImplementations.ts, 13, 12))

    return x;
>x : Symbol(x, Decl(functionImplementations.ts, 14, 7))

};

// Two mutually recursive function implementations with no return type annotations
function rec1() {
>rec1 : Symbol(rec1, Decl(functionImplementations.ts, 16, 2))

    return rec2();
>rec2 : Symbol(rec2, Decl(functionImplementations.ts, 21, 1))
}
function rec2() {
>rec2 : Symbol(rec2, Decl(functionImplementations.ts, 21, 1))

    return rec1();
>rec1 : Symbol(rec1, Decl(functionImplementations.ts, 16, 2))
}
var a = rec1();
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>rec1 : Symbol(rec1, Decl(functionImplementations.ts, 16, 2))

var a = rec2();
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>rec2 : Symbol(rec2, Decl(functionImplementations.ts, 21, 1))

// Two mutually recursive function implementations with return type annotation in one
function rec3(): number {
>rec3 : Symbol(rec3, Decl(functionImplementations.ts, 26, 15))

    return rec4();
>rec4 : Symbol(rec4, Decl(functionImplementations.ts, 31, 1))
}
function rec4() {
>rec4 : Symbol(rec4, Decl(functionImplementations.ts, 31, 1))

    return rec3();
>rec3 : Symbol(rec3, Decl(functionImplementations.ts, 26, 15))
}
var n: number;
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))

var n = rec3();
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))
>rec3 : Symbol(rec3, Decl(functionImplementations.ts, 26, 15))

var n = rec4();
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))
>rec4 : Symbol(rec4, Decl(functionImplementations.ts, 31, 1))

// FunctionExpression with no return type annotation and returns a number
var n = function () {
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))

    return 3;
} ();

// FunctionExpression with no return type annotation and returns null
var nu = null;
>nu : Symbol(nu, Decl(functionImplementations.ts, 45, 3), Decl(functionImplementations.ts, 46, 3))

var nu = function () {
>nu : Symbol(nu, Decl(functionImplementations.ts, 45, 3), Decl(functionImplementations.ts, 46, 3))

    return null;
} ();

// FunctionExpression with no return type annotation and returns undefined
var un = undefined;
>un : Symbol(un, Decl(functionImplementations.ts, 51, 3), Decl(functionImplementations.ts, 52, 3))
>undefined : Symbol(undefined)

var un = function () {
>un : Symbol(un, Decl(functionImplementations.ts, 51, 3), Decl(functionImplementations.ts, 52, 3))

    return undefined;
>undefined : Symbol(undefined)

} ();

// FunctionExpression with no return type annotation and returns a type parameter type
var n = function <T>(x: T) {
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))
>T : Symbol(T, Decl(functionImplementations.ts, 57, 18))
>x : Symbol(x, Decl(functionImplementations.ts, 57, 21))
>T : Symbol(T, Decl(functionImplementations.ts, 57, 18))

    return x;
>x : Symbol(x, Decl(functionImplementations.ts, 57, 21))

} (4);

// FunctionExpression with no return type annotation and returns a constrained type parameter type
var n = function <T extends {}>(x: T) {
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))
>T : Symbol(T, Decl(functionImplementations.ts, 62, 18))
>x : Symbol(x, Decl(functionImplementations.ts, 62, 32))
>T : Symbol(T, Decl(functionImplementations.ts, 62, 18))

    return x;
>x : Symbol(x, Decl(functionImplementations.ts, 62, 32))

} (4);

// FunctionExpression with no return type annotation with multiple return statements with identical types
var n = function () {
>n : Symbol(n, Decl(functionImplementations.ts, 35, 3), Decl(functionImplementations.ts, 36, 3), Decl(functionImplementations.ts, 37, 3), Decl(functionImplementations.ts, 40, 3), Decl(functionImplementations.ts, 57, 3), Decl(functionImplementations.ts, 62, 3), Decl(functionImplementations.ts, 67, 3))

    return 3;
    return 5;
}();

// Otherwise, the inferred return type is the first of the types of the return statement expressions
// in the function body that is a supertype of each of the others, 
// ignoring return statements with no expressions.
// A compile - time error occurs if no return statement expression has a type that is a supertype of each of the others.
// FunctionExpression with no return type annotation with multiple return statements with subtype relation between returns
class Base { private m; }
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))
>m : Symbol(Base.m, Decl(functionImplementations.ts, 77, 12))

class Derived extends Base { private q; }
>Derived : Symbol(Derived, Decl(functionImplementations.ts, 77, 25))
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))
>q : Symbol(Derived.q, Decl(functionImplementations.ts, 78, 28))

var b: Base;
>b : Symbol(b, Decl(functionImplementations.ts, 79, 3), Decl(functionImplementations.ts, 80, 3))
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))

var b = function () {
>b : Symbol(b, Decl(functionImplementations.ts, 79, 3), Decl(functionImplementations.ts, 80, 3))

    return new Base(); return new Derived();
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))
>Derived : Symbol(Derived, Decl(functionImplementations.ts, 77, 25))

} ();

// FunctionExpression with no return type annotation with multiple return statements with one a recursive call
var a = function f() {
>a : Symbol(a, Decl(functionImplementations.ts, 5, 3), Decl(functionImplementations.ts, 8, 3), Decl(functionImplementations.ts, 13, 3), Decl(functionImplementations.ts, 25, 3), Decl(functionImplementations.ts, 26, 3), Decl(functionImplementations.ts, 85, 3))
>f : Symbol(f, Decl(functionImplementations.ts, 85, 7))

    return new Base(); return new Derived(); return f(); // ?
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))
>Derived : Symbol(Derived, Decl(functionImplementations.ts, 77, 25))
>f : Symbol(f, Decl(functionImplementations.ts, 85, 7))

} ();

// FunctionExpression with non -void return type annotation with a single throw statement
undefined === function (): number {
>undefined : Symbol(undefined)

    throw undefined;
>undefined : Symbol(undefined)

};

// Type of 'this' in function implementation is 'any'
function thisFunc() {
>thisFunc : Symbol(thisFunc, Decl(functionImplementations.ts, 92, 2))

    var x = this;
>x : Symbol(x, Decl(functionImplementations.ts, 96, 7), Decl(functionImplementations.ts, 97, 7))

    var x: any;
>x : Symbol(x, Decl(functionImplementations.ts, 96, 7), Decl(functionImplementations.ts, 97, 7))
}

// Function signature with optional parameter, no type annotation and initializer has initializer's type
function opt1(n = 4) {
>opt1 : Symbol(opt1, Decl(functionImplementations.ts, 98, 1))
>n : Symbol(n, Decl(functionImplementations.ts, 101, 14))

    var m = n;
>m : Symbol(m, Decl(functionImplementations.ts, 102, 7), Decl(functionImplementations.ts, 103, 7))
>n : Symbol(n, Decl(functionImplementations.ts, 101, 14))

    var m: number;
>m : Symbol(m, Decl(functionImplementations.ts, 102, 7), Decl(functionImplementations.ts, 103, 7))
}

// Function signature with optional parameter, no type annotation and initializer has initializer's widened type
function opt2(n = { x: null, y: undefined }) {
>opt2 : Symbol(opt2, Decl(functionImplementations.ts, 104, 1))
>n : Symbol(n, Decl(functionImplementations.ts, 107, 14))
>x : Symbol(x, Decl(functionImplementations.ts, 107, 19))
>y : Symbol(y, Decl(functionImplementations.ts, 107, 28))
>undefined : Symbol(undefined)

    var m = n;
>m : Symbol(m, Decl(functionImplementations.ts, 108, 7), Decl(functionImplementations.ts, 109, 7))
>n : Symbol(n, Decl(functionImplementations.ts, 107, 14))

    var m: { x: any; y: any };
>m : Symbol(m, Decl(functionImplementations.ts, 108, 7), Decl(functionImplementations.ts, 109, 7))
>x : Symbol(x, Decl(functionImplementations.ts, 109, 12))
>y : Symbol(y, Decl(functionImplementations.ts, 109, 20))
}

// Function signature with initializer referencing other parameter to the left
function opt3(n: number, m = n) {
>opt3 : Symbol(opt3, Decl(functionImplementations.ts, 110, 1))
>n : Symbol(n, Decl(functionImplementations.ts, 113, 14))
>m : Symbol(m, Decl(functionImplementations.ts, 113, 24))
>n : Symbol(n, Decl(functionImplementations.ts, 113, 14))

    var y = m;
>y : Symbol(y, Decl(functionImplementations.ts, 114, 7), Decl(functionImplementations.ts, 115, 7))
>m : Symbol(m, Decl(functionImplementations.ts, 113, 24))

    var y: number;
>y : Symbol(y, Decl(functionImplementations.ts, 114, 7), Decl(functionImplementations.ts, 115, 7))
}

// Function signature with optional parameter has correct codegen 
// (tested above)

// FunctionExpression with non -void return type annotation return with no expression
function f6(): number {
>f6 : Symbol(f6, Decl(functionImplementations.ts, 116, 1))

    return;
}

class Derived2 extends Base { private r: string; }
>Derived2 : Symbol(Derived2, Decl(functionImplementations.ts, 124, 1))
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))
>r : Symbol(Derived2.r, Decl(functionImplementations.ts, 126, 29))

class AnotherClass { private x }
>AnotherClass : Symbol(AnotherClass, Decl(functionImplementations.ts, 126, 50))
>x : Symbol(AnotherClass.x, Decl(functionImplementations.ts, 127, 20))

// if f is a contextually typed function expression, the inferred return type is the union type
// of the types of the return statement expressions in the function body, 
// ignoring return statements with no expressions.
var f7: (x: number) => string | number = x => { // should be (x: number) => number | string
>f7 : Symbol(f7, Decl(functionImplementations.ts, 131, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 131, 9))
>x : Symbol(x, Decl(functionImplementations.ts, 131, 40))

    if (x < 0) { return x; }
>x : Symbol(x, Decl(functionImplementations.ts, 131, 40))
>x : Symbol(x, Decl(functionImplementations.ts, 131, 40))

    return x.toString();
>x.toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(functionImplementations.ts, 131, 40))
>toString : Symbol(Number.toString, Decl(lib.d.ts, --, --))
}
var f8: (x: number) => any = x => { // should be (x: number) => Base
>f8 : Symbol(f8, Decl(functionImplementations.ts, 135, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 135, 9))
>x : Symbol(x, Decl(functionImplementations.ts, 135, 28))

    return new Base();
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))

    return new Derived2();
>Derived2 : Symbol(Derived2, Decl(functionImplementations.ts, 124, 1))
}
var f9: (x: number) => any = x => { // should be (x: number) => Base
>f9 : Symbol(f9, Decl(functionImplementations.ts, 139, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 139, 9))
>x : Symbol(x, Decl(functionImplementations.ts, 139, 28))

    return new Base();
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))

    return new Derived();
>Derived : Symbol(Derived, Decl(functionImplementations.ts, 77, 25))

    return new Derived2();
>Derived2 : Symbol(Derived2, Decl(functionImplementations.ts, 124, 1))
}
var f10: (x: number) => any = x => { // should be (x: number) => Derived | Derived1
>f10 : Symbol(f10, Decl(functionImplementations.ts, 144, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 144, 10))
>x : Symbol(x, Decl(functionImplementations.ts, 144, 29))

    return new Derived();
>Derived : Symbol(Derived, Decl(functionImplementations.ts, 77, 25))

    return new Derived2();
>Derived2 : Symbol(Derived2, Decl(functionImplementations.ts, 124, 1))
}
var f11: (x: number) => any = x => { // should be (x: number) => Base | AnotherClass
>f11 : Symbol(f11, Decl(functionImplementations.ts, 148, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 148, 10))
>x : Symbol(x, Decl(functionImplementations.ts, 148, 29))

    return new Base();
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))

    return new AnotherClass();
>AnotherClass : Symbol(AnotherClass, Decl(functionImplementations.ts, 126, 50))
}
var f12: (x: number) => any = x => { // should be (x: number) => Base | AnotherClass
>f12 : Symbol(f12, Decl(functionImplementations.ts, 152, 3))
>x : Symbol(x, Decl(functionImplementations.ts, 152, 10))
>x : Symbol(x, Decl(functionImplementations.ts, 152, 29))

    return new Base();
>Base : Symbol(Base, Decl(functionImplementations.ts, 70, 4))

    return; // should be ignored
    return new AnotherClass();
>AnotherClass : Symbol(AnotherClass, Decl(functionImplementations.ts, 126, 50))
}
