You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hphp/hack/manual/hack/18-packages/03-cross-package-calls.md
+29-4Lines changed: 29 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,8 +142,6 @@ if (package foo) {
142
142
}
143
143
```
144
144
145
-
**Note:** Package expressions are currently disallowed inside `invariant()` calls due to unexpected typechecker complexity.
146
-
147
145
### Runtime Behavior
148
146
149
147
-`package foo` desugars to `package_exists("foo")`
@@ -202,7 +200,33 @@ function conditional_caller(): void {
202
200
203
201
### Package Inclusion Requirements
204
202
205
-
When using `<<__RequirePackage('a')>>` or `<<__SoftRequirePackage('a')>>` in package 'b', package 'a' must include package 'b'.
203
+
When using `<<__RequirePackage('a')>>` or `<<__SoftRequirePackage('a')>>` in package 'b', package 'a' must **strictly** include package 'b'. This means:
204
+
205
+
1.**Cannot require own package:** You cannot use `__(Soft)RequirePackage('b')` when already in package 'b'.
206
+
207
+
```hack no-extract
208
+
// File in package 'intern'
209
+
<<__RequirePackage('intern')>> // ERROR: cannot require own package
210
+
function self_require(): void {}
211
+
212
+
<<__RequirePackage('prod')>> // ERROR: prod does not include intern
213
+
function reverse_require(): void {} // (assuming intern includes prod, not vice versa)
214
+
```
215
+
216
+
2.**Must not soft-include:** If package 'b' only `soft_includes` package 'a', you cannot use `__(Soft)RequirePackage('a')` in package 'b'.
217
+
218
+
```toml
219
+
[packages.prod]
220
+
soft_includes = ["dynamically_accessible"]
221
+
```
222
+
223
+
```hack no-extract
224
+
// File in package 'prod'
225
+
<<__RequirePackage('dynamically_accessible')>> // ERROR: prod only soft-includes this package
226
+
function illegal(): void {}
227
+
```
228
+
229
+
206
230
207
231
### `__RequirePackage`
208
232
@@ -443,6 +467,7 @@ Temporary exceptions support legacy build behaviors where certain symbol referen
0 commit comments