parenthesizedContexualTyping2.ts(12,5): error TS2322: Type 'undefined' is not assignable to type 'T'.
  'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
parenthesizedContexualTyping2.ts(15,30): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(16,31): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(17,32): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(18,33): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(20,30): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(20,72): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(21,31): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(21,74): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(22,32): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(22,77): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(23,33): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(23,79): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(26,14): error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
  Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
    Type 'undefined' is not assignable to type '<T>(p: T) => T'.
parenthesizedContexualTyping2.ts(26,53): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(27,14): error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
  Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
    Type 'undefined' is not assignable to type '<T>(p: T) => T'.
parenthesizedContexualTyping2.ts(27,54): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(28,14): error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
  Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
    Type 'undefined' is not assignable to type '<T>(p: T) => T'.
parenthesizedContexualTyping2.ts(28,54): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(28,100): error TS7006: Parameter 'x' implicitly has an 'any' type.
parenthesizedContexualTyping2.ts(28,107): error TS2347: Untyped function calls may not accept type arguments.
parenthesizedContexualTyping2.ts(29,15): error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
  Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
    Type 'undefined' is not assignable to type '<T>(p: T) => T'.
parenthesizedContexualTyping2.ts(29,56): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(29,107): error TS7006: Parameter 'x' implicitly has an 'any' type.
parenthesizedContexualTyping2.ts(29,114): error TS2347: Untyped function calls may not accept type arguments.
parenthesizedContexualTyping2.ts(31,42): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(32,43): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
parenthesizedContexualTyping2.ts(35,31): error TS2322: Type 'undefined' is not assignable to type 'string'.
parenthesizedContexualTyping2.ts(35,32): error TS2695: Left side of comma operator is unused and has no side effects.
parenthesizedContexualTyping2.ts(35,55): error TS2322: Type 'undefined' is not assignable to type 'number'.
parenthesizedContexualTyping2.ts(35,56): error TS2695: Left side of comma operator is unused and has no side effects.
parenthesizedContexualTyping2.ts(36,32): error TS2322: Type 'undefined' is not assignable to type 'string'.
parenthesizedContexualTyping2.ts(36,33): error TS2695: Left side of comma operator is unused and has no side effects.
parenthesizedContexualTyping2.ts(36,56): error TS2322: Type 'undefined' is not assignable to type 'number'.
parenthesizedContexualTyping2.ts(36,57): error TS2695: Left side of comma operator is unused and has no side effects.


==== parenthesizedContexualTyping2.ts (35 errors) ====
    // These tests ensure that in cases where it may *appear* that a value has a type,
    // they actually are properly being contextually typed. The way we test this is
    // that we invoke contextually typed arguments with type arguments.
    // Since 'any' cannot be invoked with type arguments, we should get errors
    // back if contextual typing is not taking effect.
    
    type FuncType = (x: <T>(p: T) => T) => typeof x;
    
    function fun<T>(f: FuncType, x: T): T;
    function fun<T>(f: FuncType, g: FuncType, x: T): T;
    function fun<T>(...rest: any[]): T {
        return undefined;
        ~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'T'.
!!! error TS2322:   'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
    }
    
    var a = fun(x => { x<number>(undefined); return x; }, 10);
                                 ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var b = fun((x => { x<number>(undefined); return x; }), 10);
                                  ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var c = fun(((x => { x<number>(undefined); return x; })), 10);
                                   ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var d = fun((((x => { x<number>(undefined); return x; }))), 10);
                                    ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    
    var e = fun(x => { x<number>(undefined); return x; }, x => { x<number>(undefined); return x; }, 10);
                                 ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                           ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var f = fun((x => { x<number>(undefined); return x; }),(x => { x<number>(undefined); return x; }), 10);
                                  ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                             ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var g = fun(((x => { x<number>(undefined); return x; })),((x => { x<number>(undefined); return x; })), 10);
                                   ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                                ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var h = fun((((x => { x<number>(undefined); return x; }))),((x => { x<number>(undefined); return x; })), 10);
                                    ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                                  ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    
    // Ternaries in parens
    var i = fun((Math.random() < 0.5 ? x => { x<number>(undefined); return x; } : x => undefined), 10);
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
!!! error TS2345:   Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
!!! error TS2345:     Type 'undefined' is not assignable to type '<T>(p: T) => T'.
!!! related TS2793 parenthesizedContexualTyping2.ts:11:10: The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
                                                        ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var j = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), 10);
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
!!! error TS2345:   Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
!!! error TS2345:     Type 'undefined' is not assignable to type '<T>(p: T) => T'.
!!! related TS2793 parenthesizedContexualTyping2.ts:11:10: The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
                                                         ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var k = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), x => { x<number>(undefined); return x; }, 10);
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
!!! error TS2345:   Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
!!! error TS2345:     Type 'undefined' is not assignable to type '<T>(p: T) => T'.
!!! related TS2793 parenthesizedContexualTyping2.ts:11:10: The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
                                                         ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                                                       ~
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
                                                                                                              ~~~~~~~~~~~~~~~~~~~~
!!! error TS2347: Untyped function calls may not accept type arguments.
    var l = fun(((Math.random() < 0.5 ? ((x => { x<number>(undefined); return x; })) : ((x => undefined)))),((x => { x<number>(undefined); return x; })), 10);
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '((x: <T>(p: T) => T) => <T>(p: T) => T) | ((x: <T>(p: T) => T) => undefined)' is not assignable to parameter of type 'FuncType'.
!!! error TS2345:   Type '(x: <T>(p: T) => T) => undefined' is not assignable to type 'FuncType'.
!!! error TS2345:     Type 'undefined' is not assignable to type '<T>(p: T) => T'.
!!! related TS2793 parenthesizedContexualTyping2.ts:11:10: The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.
                                                           ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
                                                                                                              ~
!!! error TS7006: Parameter 'x' implicitly has an 'any' type.
                                                                                                                     ~~~~~~~~~~~~~~~~~~~~
!!! error TS2347: Untyped function calls may not accept type arguments.
    
    var lambda1: FuncType = x => { x<number>(undefined); return x; };
                                             ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    var lambda2: FuncType = (x => { x<number>(undefined); return x; });
                                              ~~~~~~~~~
!!! error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
    
    type ObjType = { x: (p: number) => string; y: (p: string) => number };
    var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
                                  ~~~~~~~~~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
!!! related TS6502 parenthesizedContexualTyping2.ts:34:21: The expected type comes from the return type of this signature.
                                   ~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
                                                          ~~~~~~~~~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
!!! related TS6502 parenthesizedContexualTyping2.ts:34:47: The expected type comes from the return type of this signature.
                                                           ~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
    var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
                                   ~~~~~~~~~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
!!! related TS6502 parenthesizedContexualTyping2.ts:34:21: The expected type comes from the return type of this signature.
                                    ~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
                                                           ~~~~~~~~~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
!!! related TS6502 parenthesizedContexualTyping2.ts:34:47: The expected type comes from the return type of this signature.
                                                            ~
!!! error TS2695: Left side of comma operator is unused and has no side effects.