Skip to content

Commit

Permalink
Do not automatically enable upcast feature under Sound Dynamic
Browse files Browse the repository at this point in the history
Summary: As the title says. We don't want upcast to slip in as a result of deploying Sound Dynamic. We probably want to rethink the syntax, and possibly integrate with a putative "type ascription" feature.

Reviewed By: vassilmladenov

Differential Revision: D45939636

fbshipit-source-id: 477e228010771be0491df85faee8668eb52150f4
  • Loading branch information
Andrew Kennedy authored and facebook-github-bot committed May 17, 2023
1 parent 54bf91e commit 0620b14
Show file tree
Hide file tree
Showing 153 changed files with 321 additions and 232 deletions.
4 changes: 1 addition & 3 deletions hphp/hack/src/parser/rust_parser_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5451,9 +5451,7 @@ impl<'a, State: 'a + Clone> ParserErrors<'a, State> {
_ => {}
},
UpcastExpression(_) => {
if !self.env.parser_options.tco_enable_sound_dynamic {
self.check_can_use_feature(node, &UnstableFeatures::UpcastExpression)
}
self.check_can_use_feature(node, &UnstableFeatures::UpcastExpression)
}
RequireClause(c) => {
if c.kind.is_class() {
Expand Down
20 changes: 14 additions & 6 deletions hphp/hack/test/integration/test_refactor_sound_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def check_upcast_cmd(
def test_no_sd(self) -> None:
self.write_and_test_one_file(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function h(shape(...) $m): int {
$x = h<> upcast dynamic;
Expand All @@ -63,6 +64,7 @@ def test_one_upcast_one_function(self) -> None:

self.write_and_test_one_file(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function h(shape(...) $m): int {
$x = h<> upcast dynamic;
Expand All @@ -71,7 +73,7 @@ def test_one_upcast_one_function(self) -> None:
"Function",
"h",
[
f'File "{self.test_driver.repo_dir}/a.php", line 4, characters 20-37:',
f'File "{self.test_driver.repo_dir}/a.php", line 5, characters 20-37:',
],
)

Expand All @@ -80,7 +82,7 @@ def test_one_upcast_one_class(self) -> None:
self.write_and_test_one_file(
"""
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class Counter {
private int $i = 0;
Expand All @@ -103,6 +105,7 @@ class Counter {
def test_one_upcast_multiple_function(self) -> None:
self.write_and_test_one_file(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function h(shape(...) $m): int {
$x = h<> upcast dynamic;
Expand All @@ -115,14 +118,15 @@ def test_one_upcast_multiple_function(self) -> None:
"Function",
"h",
[
f'File "{self.test_driver.repo_dir}/a.php", line 4, characters 20-37:',
f'File "{self.test_driver.repo_dir}/a.php", line 5, characters 20-37:',
],
)

def test_multiple_files(self) -> None:
with open(os.path.join(self.test_driver.repo_dir, "a.php"), "w") as f:
f.write(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function h(shape(...) $m): int {
$x = h<> upcast dynamic;
Expand All @@ -137,6 +141,8 @@ def test_multiple_files(self) -> None:
with open(os.path.join(self.test_driver.repo_dir, "b.php"), "w") as f:
f.write(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function b(dynamic $d): void {
$y = h<> upcast dynamic;
$d(3);
Expand All @@ -147,6 +153,8 @@ def test_multiple_files(self) -> None:
with open(os.path.join(self.test_driver.repo_dir, "c.php"), "w") as f:
f.write(
"""<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function c(int $i): void {
$z = h<> upcast dynamic;
}
Expand All @@ -161,8 +169,8 @@ def test_multiple_files(self) -> None:
"Function",
"h",
[
f'File "{self.test_driver.repo_dir}/a.php", line 4, characters 20-37:',
f'File "{self.test_driver.repo_dir}/b.php", line 3, characters 24-41:',
f'File "{self.test_driver.repo_dir}/c.php", line 3, characters 24-41:',
f'File "{self.test_driver.repo_dir}/a.php", line 5, characters 20-37:',
f'File "{self.test_driver.repo_dir}/b.php", line 5, characters 24-41:',
f'File "{self.test_driver.repo_dir}/c.php", line 5, characters 24-41:',
],
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
class C {
Expand Down
36 changes: 18 additions & 18 deletions hphp/hack/test/refactor_sd/dump_constraints/class/class.php.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ Constraints for \C::m:
Constraints for \C::static_m:

Constraints for \simple_upcast1:
?1 ⊆ [12:3-17]
Function call at [12:3-17]
Introduction at [11:8-16]
?1 ⊆ [13:3-17]
Function call at [13:3-17]
Introduction at [12:8-16]
Upcast at ?1
[11:8-16] ⊆ ?1
[12:8-16] ⊆ ?1

Constraints for \simple_upcast2:
?2 ⊆ [17:3-10]
?2 ⊆ [17:3-8]
Function call at [17:3-10]
Function call at [17:3-8]
Introduction at [16:8-15]
?2 ⊆ [18:3-10]
?2 ⊆ [18:3-8]
Function call at [18:3-10]
Function call at [18:3-8]
Introduction at [17:8-15]
Upcast at ?2
[16:8-15] ⊆ ?2
[17:8-15] ⊆ ?2

Constraints for \simple_upcast3:
?3 ⊆ [22:3-17]
Function call at [22:3-17]
Introduction at [21:8-15]
?3 ⊆ [23:3-17]
Function call at [23:3-17]
Introduction at [22:8-15]
Upcast at ?3
[21:8-15] ⊆ ?3
[22:8-15] ⊆ ?3

Constraints for \simple_upcast4:
?4 ⊆ [27:3-10]
Function call at [27:3-10]
Introduction at [26:8-15]
?4 ⊆ [28:3-10]
Function call at [28:3-10]
Introduction at [27:8-15]
Upcast at ?4
[26:8-15] ⊆ ?4
[27:8-15] ⊆ ?4

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
class C {
Expand Down
72 changes: 36 additions & 36 deletions hphp/hack/test/refactor_sd/dump_constraints/class/class2.php.exp
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@ Constraints for \C::static_m:
Constraints for \D::m:

Constraints for \if_test:
?3 ⊆ [34:7-34]
?3 ⊆ [34:7-36]
?4 ⊆ [45:3-25]
?4 ⊆ [45:3-27]
?5 ⊆ [40:7-21]
?5 ⊆ [46:3-25]
?5 ⊆ [46:3-27]
?6 ⊆ [42:7-35]
?6 ⊆ [42:7-37]
Function call at [34:7-34]
Function call at [34:7-36]
Function call at [40:7-21]
Function call at [42:7-35]
Function call at [42:7-37]
Function call at [45:3-25]
Function call at [45:3-27]
?3 ⊆ [35:7-34]
?3 ⊆ [35:7-36]
?4 ⊆ [46:3-25]
?4 ⊆ [46:3-27]
?5 ⊆ [41:7-21]
?5 ⊆ [47:3-25]
?5 ⊆ [47:3-27]
?6 ⊆ [43:7-35]
?6 ⊆ [43:7-37]
Function call at [35:7-34]
Function call at [35:7-36]
Function call at [41:7-21]
Function call at [43:7-35]
Function call at [43:7-37]
Function call at [46:3-25]
Function call at [46:3-27]
Introduction at [34:8-15]
Introduction at [38:12-19]
Introduction at [39:12-20]
Introduction at [42:8-16]
Function call at [47:3-25]
Function call at [47:3-27]
Introduction at [35:8-15]
Introduction at [39:12-19]
Introduction at [40:12-20]
Introduction at [43:8-16]
Upcast at ?3
Upcast at ?4
Upcast at ?5
Upcast at ?6
[34:8-15] ⊆ ?3
[38:12-19] ⊆ ?4
[39:12-20] ⊆ ?5
[42:8-16] ⊆ ?6
[35:8-15] ⊆ ?3
[39:12-19] ⊆ ?4
[40:12-20] ⊆ ?5
[43:8-16] ⊆ ?6

Constraints for \while_test:
?1 ⊆ [18:7-34]
?1 ⊆ [18:7-36]
?2 ⊆ [19:7-35]
?2 ⊆ [19:7-37]
Function call at [18:7-34]
Function call at [18:7-36]
Function call at [19:7-35]
Function call at [19:7-37]
Introduction at [18:8-15]
Introduction at [19:8-16]
?1 ⊆ [19:7-34]
?1 ⊆ [19:7-36]
?2 ⊆ [20:7-35]
?2 ⊆ [20:7-37]
Function call at [19:7-34]
Function call at [19:7-36]
Function call at [20:7-35]
Function call at [20:7-37]
Introduction at [19:8-15]
Introduction at [20:8-16]
Upcast at ?1
Upcast at ?2
[18:8-15] ⊆ ?1
[19:8-16] ⊆ ?2
[19:8-15] ⊆ ?1
[20:8-16] ⊆ ?2

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function f(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Constraints for \f:

Constraints for \h:
Introduction at [7:8-11]
Introduction at [9:8-11]
Introduction at [10:8-11]
Introduction at [8:8-11]
Upcast at ?1
Upcast at ?1
Upcast at ?2
[7:8-11] ⊆ ?1
[9:8-11] ⊆ ?2
[10:8-11] ⊆ ?2
[8:8-11] ⊆ ?1

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function g(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Constraints for \f:
Constraints for \g:

Constraints for \h:
Introduction at [10:8-11]
Introduction at [15:8-11]
Introduction at [11:8-11]
Introduction at [16:8-11]
Upcast at ?2
[10:8-11] ⊆ ?1
[15:8-11] ⊆ ?2
[11:8-11] ⊆ ?1
[16:8-11] ⊆ ?2

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function f(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Constraints for \f:

Constraints for \h:
Introduction at [7:20-23]
Introduction at [8:20-23]
Upcast at ?1
[7:20-23] ⊆ ?1
[8:20-23] ⊆ ?1

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function f(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Constraints for \f:

Constraints for \h:
?1 ⊆ [8:3-7]
Function call at [8:3-7]
Introduction at [7:8-11]
[7:8-11] ⊆ ?1
?1 ⊆ [9:3-7]
Function call at [9:3-7]
Introduction at [8:8-11]
[8:8-11] ⊆ ?1

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function f(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Constraints for \f:

Constraints for \h:
?2 ⊆ [9:3-7]
Function call at [9:3-7]
Introduction at [10:8-11]
Introduction at [7:8-11]
?2 ⊆ [10:3-7]
Function call at [10:3-7]
Introduction at [11:8-11]
Introduction at [8:8-11]
Introduction at [9:8-11]
Upcast at ?1
Upcast at ?2
Upcast at ?3
[10:8-11] ⊆ ?3
[7:8-11] ⊆ ?1
[8:8-11] ⊆ ?2
[11:8-11] ⊆ ?3
[8:8-11] ⊆ ?1
[9:8-11] ⊆ ?2

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

<<__SupportDynamicType>>
function f(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Constraints for \f:
Constraints for \g:

Constraints for \h:
?2 ⊆ [12:3-7]
?2 ⊆ [13:3-7]
Function call at [12:3-7]
?2 ⊆ [14:3-7]
Function call at [13:3-7]
Introduction at [10:8-11]
Function call at [14:3-7]
Introduction at [11:8-11]
Introduction at [14:8-11]
Introduction at [12:8-11]
Introduction at [15:8-11]
Upcast at ?1
Upcast at ?2
Upcast at ?3
[10:8-11] ⊆ ?1
[11:8-11] ⊆ ?2
[14:8-11] ⊆ ?3
[11:8-11] ⊆ ?1
[12:8-11] ⊆ ?2
[15:8-11] ⊆ ?3

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>

function f(): int {
return 1;
Expand Down
Loading

0 comments on commit 0620b14

Please sign in to comment.