| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Flags: --harmony-types | 5 // Flags: --harmony-types |
| 6 | 6 |
| 7 function CheckValid(type) { | |
| 8 // print("V:", type); | |
| 9 assertDoesNotThrow("'use types'; var x: " + type + ";"); | |
| 10 } | |
| 11 | 7 |
| 12 function CheckInvalid(type) { | 8 load("test/mjsunit/harmony/typesystem/testgen.js"); |
| 13 // print("I:", type); | 9 |
| 14 assertThrows("'use types'; var x: " + type + ";", SyntaxError); | |
| 15 } | |
| 16 | 10 |
| 17 (function TestParametricFunctionTypes() { | 11 (function TestParametricFunctionTypes() { |
| 18 CheckValid("<A> (x: A) => A"); | 12 CheckValidType("<A> (x: A) => A"); |
| 19 CheckValid("<A extends string> (x: A) => A"); | 13 CheckValidType("<A extends string> (x: A) => A"); |
| 20 CheckValid("<A, B> (x: A, y: B) => A"); | 14 CheckValidType("<A, B> (x: A, y: B) => A"); |
| 21 CheckValid("<A, B extends number[], C> (x: A, y: B) => C"); | 15 CheckValidType("<A, B extends number[], C> (x: A, y: B) => C"); |
| 22 CheckValid("<A, B, C, D> (x: A, y: B, z: C[], d: (e: D) => D) => A"); | 16 CheckValidType("<A, B, C, D> (x: A, y: B, z: C[], d: (e: D) => D) => A"); |
| 23 // Type parameter lists in non-function types. | 17 // Type parameter lists in non-function types. |
| 24 CheckInvalid("<A> A[]"); | 18 CheckInvalidType("<A> A[]"); |
| 25 // Empty type parameter list is disallowed. | 19 // Empty type parameter list is disallowed. |
| 26 CheckInvalid("<> (x: number) => number"); | 20 CheckInvalidType("<> (x: number) => number"); |
| 27 // Invalid type in extends. | 21 // Invalid type in extends. |
| 28 CheckInvalid("<A extends ()> (x: A) => A"); | 22 CheckInvalidType("<A extends ()> (x: A) => A"); |
| 29 })(); | 23 })(); |
| 30 | 24 |
| 31 (function TestParametricTypeReferences() { | 25 (function TestParametricTypeReferences() { |
| 32 CheckValid("Tree<number>"); | 26 CheckValidType("Tree<number>"); |
| 33 CheckValid("Map<string, number>"); | 27 CheckValidType("Map<string, number>"); |
| 34 // Invalid types as arguments. | 28 // Invalid types as arguments. |
| 35 CheckInvalid("Map<string, (number, void)>"); | 29 CheckInvalidType("Map<string, (number, void)>"); |
| 36 // Type arguments not in type references. | 30 // Type arguments not in type references. |
| 37 CheckInvalid("number<string>"); | 31 CheckInvalidType("number<string>"); |
| 38 // Empty type argument list is disallowed. | 32 // Empty type argument list is disallowed. |
| 39 CheckInvalid("Foo<>"); | 33 CheckInvalidType("Foo<>"); |
| 40 })(); | 34 })(); |
| OLD | NEW |