Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7.2 fn closure - nullable parameters with return type #2708

Closed
michalbundyra opened this issue Nov 19, 2019 · 3 comments
Closed

PHP 7.2 fn closure - nullable parameters with return type #2708

michalbundyra opened this issue Nov 19, 2019 · 3 comments
Milestone

Comments

@michalbundyra
Copy link
Contributor

Relates to #2523

Example:

<?php

$a = fn (?\DateTime $x) : ?\DateTime => $x;

tokenized as:

        Process token 0 on line 1 [col:1;len:5;lvl:0;]: T_OPEN_TAG => <?php\n
        Process token 1 on line 2 [col:1;len:0;lvl:0;]: T_WHITESPACE => \n
        Process token 2 on line 3 [col:1;len:2;lvl:0;]: T_VARIABLE => $a
        Process token 3 on line 3 [col:3;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 4 on line 3 [col:4;len:1;lvl:0;]: T_EQUAL => =
        Process token 5 on line 3 [col:5;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 6 on line 3 [col:6;len:2;lvl:0;]: T_FN => fn
        Process token 7 on line 3 [col:8;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 8 on line 3 [col:9;len:1;lvl:0;]: T_OPEN_PARENTHESIS => (
        Process token 9 on line 3 [col:10;len:1;lvl:0;]: T_INLINE_THEN => ?       // <!-- should be T_NULLABLE 
        Process token 10 on line 3 [col:11;len:1;lvl:0;]: T_NS_SEPARATOR => \
        Process token 11 on line 3 [col:12;len:8;lvl:0;]: T_STRING => DateTime
        Process token 12 on line 3 [col:20;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 13 on line 3 [col:21;len:2;lvl:0;]: T_VARIABLE => $x
        Process token 14 on line 3 [col:23;len:1;lvl:0;]: T_CLOSE_PARENTHESIS => )
        Process token 15 on line 3 [col:24;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 16 on line 3 [col:25;len:1;lvl:0;]: T_INLINE_ELSE => :      // <!-- should be T_COLON
        Process token 17 on line 3 [col:26;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 18 on line 3 [col:27;len:1;lvl:0;]: T_NULLABLE => ?
        Process token 19 on line 3 [col:28;len:1;lvl:0;]: T_NS_SEPARATOR => \
        Process token 20 on line 3 [col:29;len:8;lvl:0;]: T_STRING => DateTime
        Process token 21 on line 3 [col:37;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 22 on line 3 [col:38;len:2;lvl:0;]: T_DOUBLE_ARROW => =>
        Process token 23 on line 3 [col:40;len:1;lvl:0;]: T_WHITESPACE => ·
        Process token 24 on line 3 [col:41;len:2;lvl:0;]: T_VARIABLE => $x
        Process token 25 on line 3 [col:43;len:1;lvl:0;]: T_SEMICOLON => ;
        Process token 26 on line 3 [col:44;len:0;lvl:0;]: T_WHITESPACE => \n

also in src/Tokenizers/PHP.php we are missing the following two ignored tokens:

image

as we can have any FQN in return type hint definition of the closure (ie ?\DateTime).

@jrfnl
Copy link
Contributor

jrfnl commented Nov 19, 2019

@michalbundyra Great catch! And thank you for all the recent tests you've been running related to the arrow functions ❤️

@gsherwood
Copy link
Member

thank you for all the recent tests you've been running related to the arrow functions

Big thanks from me as well

@gsherwood
Copy link
Member

I've fixed up the detection of T_NULLABLE in the tokenizer to resolve one of the issues. The other was resolved by the change you showed in the screenshot above. Thanks again.

gsherwood added a commit that referenced this issue Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants