Add position metadata to desugaring
[hiphop-php.git] / hphp / hack / test / typecheck / expression_trees / splice_state.php
blobf8ad1f0650e8c6472c89a67eb4a71e855c383c75
1 <?hh
3 <<file:__EnableUnstableFeatures('expression_trees')>>
5 class Foo {
6 public ?int $x;
7 public function reset(): int {
8 return 1;
12 function lift<T>(T $_): ExprTree<Code, Code::TAst, T> {
13 throw new Exception();
16 // This technically shouldn't throw an error.
17 // It currently is due to typechecking the current desugaring
18 // So, for the moment, allow this error to be thrown and fix the desugaring
19 function test(): void {
20 $x = new Foo();
22 if ($x->x !== null) {
23 $_ = Code`() ==> {
24 // We know that $x->x is not null
25 __splice__(lift($x->x + 1));
26 return;
27 }`;
31 //// BEGIN DEFS
32 // Placeholder definition so we don't get naming/typing errors.
33 final class Code {
34 const type TAst = mixed;
35 // Simple literals.
36 public function intLiteral(?ExprPos $_, int $_): this::TAst {
37 throw new Exception();
39 public function boolLiteral(?ExprPos $_, bool $_): this::TAst {
40 throw new Exception();
42 public function stringLiteral(?ExprPos $_, string $_): this::TAst {
43 throw new Exception();
45 public function nullLiteral(?ExprPos $_): this::TAst {
46 throw new Exception();
48 public function localVar(?ExprPos $_, string $_): this::TAst {
49 throw new Exception();
51 public function lambdaLiteral(
52 ?ExprPos $_,
53 vec<string> $_args,
54 vec<this::TAst> $_body,
55 ): this::TAst {
56 throw new Exception();
59 // Operators
60 public function plus(
61 ?ExprPos $_,
62 this::TAst $_,
63 this::TAst $_,
64 ): this::TAst {
65 throw new Exception();
67 public function ampamp(
68 ?ExprPos $_,
69 this::TAst $_,
70 this::TAst $_,
71 ): this::TAst {
72 throw new Exception();
74 public function barbar(
75 ?ExprPos $_,
76 this::TAst $_,
77 this::TAst $_,
78 ): this::TAst {
79 throw new Exception();
81 public function exclamationMark(
82 ?ExprPos $_,
83 this::TAst $_,
84 ): this::TAst {
85 throw new Exception();
87 public function call(
88 ?ExprPos $_,
89 string $_fnName,
90 vec<this::TAst> $_args,
91 ): this::TAst {
92 throw new Exception();
95 public function assign(
96 ?ExprPos $_,
97 this::TAst $_,
98 this::TAst $_,
99 ): this::TAst {
100 throw new Exception();
103 // Statements.
104 public function ifStatement(
105 ?ExprPos $_,
106 this::TAst $_cond,
107 vec<this::TAst> $_then_body,
108 vec<this::TAst> $_else_body,
109 ): this::TAst {
110 throw new Exception();
112 public function whileStatement(
113 ?ExprPos $_,
114 this::TAst $_cond,
115 vec<this::TAst> $_body,
116 ): this::TAst {
117 throw new Exception();
119 public function returnStatement(
120 ?ExprPos $_,
121 ?this::TAst $_,
122 ): this::TAst {
123 throw new Exception();
125 public function forStatement(
126 ?ExprPos $_,
127 vec<this::TAst> $_,
128 this::TAst $_,
129 vec<this::TAst> $_,
130 vec<this::TAst> $_,
131 ): this::TAst {
132 throw new Exception();
134 public function breakStatement(?ExprPos $_): this::TAst {
135 throw new Exception();
137 public function continueStatement(?ExprPos $_,): this::TAst {
138 throw new Exception();
141 // Splice
142 public function splice<T>(
143 ?ExprPos $_,
144 ExprTree<this, this::TAst, T> $_,
145 ): this::TAst {
146 throw new Exception();
149 // TODO: Discard unsupported syntax nodes while lowering
150 public function unsupportedSyntax(string $msg): this::TAst {
151 throw new Exception($msg);
155 final class ExprTree<TVisitor, TResult, TInfer>{
156 public function __construct(
157 private ?ExprPos $pos,
158 private (function(TVisitor): TResult) $x,
159 private (function(): TInfer) $err,
160 ) {}
163 final class ExprPos {
164 public function __construct(
165 private int $begin_line,
166 private int $begin_col,
167 private int $end_line,
168 private int $end_col,
169 ) {}
171 //// END DEFS