Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --harmony-types | |
| 6 | |
| 7 | |
| 8 load("test/mjsunit/harmony/typesystem/testgen.js"); | |
| 9 | |
| 10 | |
| 11 (function TestMethodDefinitions() { | |
| 12 // Normal methods. | |
| 13 CheckValid("class C { m(a: number, b: number) { return a+b; } }"); | |
| 14 CheckValid("class C { m(a: number, b?: number) { return a; } }"); | |
| 15 CheckValid("class C { m(a?: number, b?: number) { return 42; } }"); | |
| 16 CheckValid("class C { m(a: number, ...rest: number[]) {} }"); | |
| 17 CheckValid("class C { m(a?: number, ...rest: number[]) {} }"); | |
| 18 CheckValid("class C { m() : boolean { return true; } }"); | |
| 19 CheckValid("class C { m(a: number, b: number) : boolean { return true; } }"); | |
| 20 CheckValid("class C { m(a: number, b?: number) : boolean { return true; } }"); | |
| 21 CheckValid("class C { m(a?: number, b?: number) : boolean { return true; } }") ; | |
| 22 CheckValid("class C { m(a: number, ...rest: number[]) : void {} }"); | |
| 23 CheckValid("class C { m(a: number, ...rest: number[]) : void {} }"); | |
| 24 CheckValid("class C { m([first, ...rest]: number[]) : void {} }"); | |
| 25 CheckValid("class C { m(a: number = 7, b: number) { return a+b; } }"); | |
| 26 CheckValid("class C { m(a: number = 1, b?: number) { return a; } }"); | |
| 27 CheckValid("class C { m(a: number = 2, ...rest: number[]) {} }"); | |
| 28 CheckValid("class C { m(a: number = 1, b: number) : boolean { return true; } } "); | |
| 29 CheckValid("class C { m(a: number = 1, b?: number) : boolean { return true; } }"); | |
| 30 CheckValid("class C { m(a: number = 1, ...rest: number[]) : void {} }"); | |
| 31 CheckValid("class C { m([first, ...rest]: number[] = [1]) : void {} }"); | |
| 32 // Type parametric. | |
| 33 CheckValid("class C { m <A>(a: A, b: A) { return a+b; } }"); | |
| 34 CheckValid("class C { m <A extends number>(a: A, b: A) { return a+b; } }"); | |
| 35 CheckValid("class C { m <A, B>(a: A, b: B) { return a+b; } }"); | |
| 36 CheckValid("class C { m <A extends number, B extends number>(a: A, b: B) { ret urn a+b; } }"); | |
| 37 // Constructors. | |
| 38 CheckValid("class C { constructor () {} }"); | |
| 39 CheckValid("class C { constructor (a : number) {} }"); | |
| 40 CheckValid("class C { constructor (a? : number) {} }"); | |
| 41 CheckValid("class C { constructor (a : number, b : string) {} }"); | |
| 42 CheckValid("class C { constructor (a, b? : string) {} }"); | |
| 43 CheckValid("class C { constructor (a, b? : string, ...rest: any[]) {} }"); | |
| 44 // Getters. | |
| 45 CheckValid("class C { get x () { return 42; } }"); | |
| 46 CheckValid("class C { get x () : number { return 42; } }"); | |
| 47 // Setters. | |
| 48 CheckValid("class C { set x (a) {} }"); | |
| 49 CheckValid("class C { set x (a) : void {} }"); | |
| 50 CheckValid("class C { set x (a : number) {} }"); | |
| 51 CheckValid("class C { set x (a : number) : void {} }"); | |
| 52 // Invalid constructors. | |
| 53 CheckInvalid("class C { constructor (a : number) : boolean {} }"); | |
| 54 CheckInvalid("class C { constructor <A>(a : A) {} }"); | |
| 55 // Invalid getters. | |
|
rossberg
2016/04/18 09:22:24
What about "get x(y?) {}"?
nickie
2016/04/19 10:58:10
Done.
| |
| 56 CheckInvalid("class C { get x (a) { return 42; } }"); | |
| 57 CheckInvalid("class C { get x (a) : number { return 42; } }"); | |
| 58 CheckInvalid("class C { get x (a, b) { return 42; } }"); | |
| 59 CheckInvalid("class C { get x (a, b) : number { return 42; } }"); | |
| 60 CheckInvalid("class C { get x (a : number) { return 42; } }"); | |
| 61 CheckInvalid("class C { get x (a : number) : number { return 42; } }"); | |
| 62 CheckInvalid("class C { get x <A>() { return 42; } }"); | |
| 63 // Invalid setters. | |
|
rossberg
2016/04/18 09:22:24
Same here: "set x(y?) {}", is that legal?
nickie
2016/04/19 10:58:10
It's not legal and unfortunately it passes. I'm a
| |
| 64 CheckInvalid("class C { set x () {} }"); | |
| 65 CheckInvalid("class C { set x () : void {} }"); | |
| 66 CheckInvalid("class C { set x (a : number, b : number) {} }"); | |
| 67 CheckInvalid("class C { set x (a : number, b : number) : void {} }"); | |
| 68 CheckInvalid("class C { set x (...rest) {} }"); | |
| 69 CheckInvalid("class C { set x (...rest : string[]) : void {} }"); | |
| 70 CheckInvalid("class C { set x <A>(a : A) {} }"); | |
| 71 })(); | |
| OLD | NEW |