New inference: improved error message for unresolved type
[hiphop-php.git] / hphp / hack / test / typecheck / xhp_attr_1.php
blob7cfdeae8b6eefa69ee51266290a70dbee9b66848
1 <?hh // strict
2 class :blah {}
3 class GenericClass<T> {}
4 class SomeClass {
5 public function bar(): float {
6 return 3.14;
9 class :foo {
10 attribute
11 // Using array without type parameters is okay for now
12 array bar-baz = array(),
13 // Using GenericClass without type parameters is okay for now
14 /* HH_FIXME[4101] */
15 GenericClass yo @required,
16 // Check to make sure that "->:" parses correctly when chained
17 // together in a larger expression.
18 SomeClass some-obj @required,
19 // An XHP class name can be used as a type hint; marking it
20 // with "@required" so the typechecker knows it can't be null
21 :blah fizz-buzz @required,
22 // If it's not marked "@required" and is doesn't have a non-null
23 // default value, then the typechecker treats it as nullable
24 :blah might-be-null,
25 // Make sure the weird trait importation syntax works when
26 // interleaved with normal XHP attribute declarations
27 :blah,
28 // An XHP attribute annoted as "string" can contain Stringish
29 // values for now
30 string string:attr-might-be:stringish = '',
31 // Make sure that attribute names with colons work fine
32 string name:with:colon;
34 function test1(:foo $obj): :blah {
35 return $obj->:fizz-buzz;
37 function test2(:foo $obj): ?:blah {
38 return $obj->:might-be-null;
40 function test3(:foo $obj): Stringish {
41 return $obj->:string:attr-might-be:stringish;
43 function test4(:foo $obj): float {
44 return $obj->:some-obj->bar();
46 function test5(:foo $obj): ?string {
47 return $obj->:name:with:colon;