rfc:match_expression

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:match_expression [2020/04/24 20:19] – Remove unused sentence ilijatovilorfc:match_expression [2020/04/25 10:37] – Specify voting time range ilijatovilo
Line 2: Line 2:
   * Date: 2020-04-12   * Date: 2020-04-12
   * Author: Ilija Tovilo, tovilo.ilija@gmail.com   * Author: Ilija Tovilo, tovilo.ilija@gmail.com
-  * Status: Under Discussion+  * Status: Voting
   * Target Version: PHP 8.0   * Target Version: PHP 8.0
   * Implementation: https://github.com/php/php-src/pull/5371   * Implementation: https://github.com/php/php-src/pull/5371
Line 212: Line 212:
 </code> </code>
  
-For the time being the following code will result in a compilation error:+For the time being using blocks in match expressions that use the return value in any way results in a compilation error:
  
 <code php> <code php>
Line 218: Line 218:
     0 => {},     0 => {},
 }; };
 +//> Match that is not used as a statement can't contain blocks
  
-//> Match that not used as a statement can't contain blocks+foo(match ($x) { 
 +    0 => {}, 
 +}); 
 +//> Match that is not used as a statement can't contain blocks 
 + 
 +1 + match ($x) { 
 +    0 => {}, 
 +}; 
 +//> Match that is not used as a statement can't contain blocks 
 + 
 +//etc. 
 + 
 +// Only allowed form 
 +match ($x) { 
 +    0 => {}, 
 +}
 </code> </code>
  
Line 245: Line 261:
 </code> </code>
  
-This introduces an ambiguity with the ''+'' and ''-'' prefix operators.+This introduces an ambiguity with the ''+'' and ''-'' unary operators.
  
 <code php> <code php>
Line 261: Line 277:
 </code> </code>
  
-When ''match'' appears as the first element of a statement would always be parsed as option 1 because there are no legitimate use cases for binary operations at a statement level. All other cases work as expected.+''match'' that appears as the first element of a statement would always be parsed as option 1 because there are no legitimate use cases for binary operations at a statement level. All other cases work as expected.
  
 <code php> <code php>
Line 307: Line 323:
 </code> </code>
  
-The keyword ''match'' could be a bit misleading here. Because I have no strong opinion on this it will be moved to a secondary vote.+The keyword ''match'' could be a bit misleading here. A potential gotcha is passing truthy values to the match which will not work as intended. But of course this issue remains regardless of dropping ''(true)'' or not. 
 + 
 +<code php> 
 +match { 
 +    preg_match(...) => {}, // preg_match returns 1 which is NOT identical (===) to true 
 +
 +</code> 
 + 
 +Because I have no strong opinion on this it will be moved to a secondary vote.
  
 ===== Miscellaneous ===== ===== Miscellaneous =====
 ==== Arbitrary expressions ==== ==== Arbitrary expressions ====
-A match condition can be any arbitrary expression. Analogous to ''switch'' each condition will be checked from top to bottom until the first one matches. If a condition matches the remaining conditions won't be evaluated+A match condition can be any arbitrary expression. Analogous to ''switch'' each condition will be checked from top to bottom until the first one matches. If a condition matches the remaining conditions won't be evaluated.
  
 <code php> <code php>
Line 413: Line 437:
  
     // Algebraic data types if we ever get them     // Algebraic data types if we ever get them
-    let Ast\BinaryExpr($lhs, '+', $rhs) => ...,+    let Ast::BinaryExpr($lhs, '+', $rhs) => ...,
 } }
  
Line 505: Line 529:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 +Voting starts 2020-04-25 and ends 2020-05-09. 
 +
 As this is a language change, a 2/3 majority is required. As this is a language change, a 2/3 majority is required.
  
-<doodle title="Would you like to add match expressions to the language?" auth="ilijatovilo" voteType="single" closed="true">+<doodle title="Would you like to add match expressions to the language?" auth="ilijatovilo" voteType="single" closed="false">
    * Yes    * Yes
    * No    * No
Line 514: Line 540:
 Secondary vote (choice with the most votes is picked): Secondary vote (choice with the most votes is picked):
  
-<doodle title="Should the semicolon for match in statement form be optional?" auth="ilijatovilo" voteType="single" closed="true">+<doodle title="Should the semicolon for match in statement form be optional?" auth="ilijatovilo" voteType="single" closed="false">
    * Yes    * Yes
    * No    * No
Line 521: Line 547:
 Secondary vote (choice with the most votes is picked): Secondary vote (choice with the most votes is picked):
  
-<doodle title="Should we allow dropping (true) condition?" auth="ilijatovilo" voteType="single" closed="true">+<doodle title="Should we allow dropping (true) condition?" auth="ilijatovilo" voteType="single" closed="false">
    * Yes    * Yes
    * No    * No
Line 528: Line 554:
 ==== If you voted no, why? ==== ==== If you voted no, why? ====
  
-  1. Not interested +  Not interested 
-  2. I don't want blocks +  I don't want blocks 
-  3. Missing return values in blocks +  Missing return values in blocks 
-  4. Missing pattern matching +  Missing pattern matching 
-  5. Missing explicit fallthrough +  Missing explicit fallthrough 
-  6. BC break is not acceptable +  BC break is not acceptable 
-  7. Other+  - Wanted [[https://wiki.php.net/rfc/switch_expression|switch expressions]] instead 
 +  - Other
  
-<doodle title="If you voted no, why?" auth="ilijatovilo" voteType="multi" closed="true">+<doodle title="If you voted no, why?" auth="ilijatovilo" voteType="multi" closed="false">
    * 1    * 1
    * 2    * 2
Line 544: Line 571:
    * 6    * 6
    * 7    * 7
 +   * 8
 </doodle> </doodle>
  
rfc/match_expression.txt · Last modified: 2020/05/09 15:59 by ilijatovilo