Float ranges: exclusive bounds in PHPDoc, rounded bound literals and readable descriptions
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- php
- Domínio
- backend-api-design
Direção de pesquisa
Start by reading the float range handling and PHPDoc parsing code, then inspect tests for float types and PHPDoc bounds. The issue leaves the exclusive-bound notation and several behavior choices open, so first agree on scope and notation with maintainers. Done means the selected behavior is covered by tests for parsing, displayed descriptions, and any new float range names.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Feature request
Float ranges keep both bounds inclusive and express a strict comparison by moving the bound to the adjacent double. In the type system this is exact: for every double $x, $x > 1.5 holds exactly when $x >= 1.5000000000000002. The PHPDoc side has no counterpart for it, though, and that shows in three places: writing such a type, reading it in messages, and a typo that silently flips its meaning. I'd like to settle how PHPDoc should handle exclusive bounds and to fix the smaller parts that do not depend on it.
Current behaviour (2.3.6)
| Code | Type |
|---|---|
if ($n > 1.5) |
float<1.5000000000000002, max> |
if ($n >= 1.5) |
float<1.5, max> |
if ($n > 0.1 + 0.2) |
float<0.3000000000000001, max> |
if ($n > 0) |
float<5.0E-324, max> |
@param positive-float |
float<5.0E-324, max> |
@param negative-float |
float<min, -5.0E-324> |
@param non-positive-float |
float<min, 0.0> |
@param non-negative-float |
float<0.0, max> |
@param finite-float |
float<-1.7976931348623157E+308, 1.7976931348623157E+308> |
@param non-zero-float |
unresolvable |
@param float<1.5000000000000001, max> |
float<1.5, max> |
Problems
- An exclusive bound has to be written as the adjacent double. "Greater than 1.5" is
float<1.5000000000000002, max>, which works and matches the narrowed type, but the writer has to find that value first. - A bound literal close to the intended one can silently flip the meaning. PHP rounds
1.5000000000000001to1.5(https://3v4l.org/c6HrD), sofloat<1.5000000000000001, max>includes 1.5, the opposite of what a writer aiming at "greater than 1.5" meant. Nothing is reported. - Messages show the adjacent double. For example
expects float<1.5000000000000002, max>, float<1.5, max> given.$n > 0is shown asfloat<5.0E-324, max>although it is exactlypositive-float, and the named float types are never shown by name. For integers,int<1, max>instead ofpositive-intis still readable; for floats the bound turns into5.0E-324. - Some names are missing. There is no
non-zero-float, unlikenon-zero-int.positive-floatandnon-negative-floatincludeINF, and a finite positive float can only be written asfloat<5.0E-324, 1.7976931348623157E+308>.
Options
- A. Syntax for exclusive bounds in PHPDoc. A way to mark a bound of
float<…>as exclusive. This needs a phpdoc-parser change and a decision on the notation, so it is the largest of the options. - B. Describe exclusive bounds and named ranges readably. Print the four sign ranges as
positive-float,negative-float,non-positive-floatandnon-negative-float. A bound that is the adjacent double of a shorter decimal could also be printed as excluding that decimal, but without option A that output could not be written back into PHPDoc. - C. Report a bound literal that rounds to a different, shorter float. For example, report
1.5000000000000001as the same float as1.5. A literal like0.1, whose shortest representation is the written text, is not reported, so the rule should be quiet on ordinary bounds. - D. Add missing names.
non-zero-float, and possibly finite variants of the sign types.
Open points
- The notation for option A, or whether exclusive bounds stay expressible only through the adjacent double and the named types. The named types already cover the most common exclusive bounds, those at zero.
- How far option B goes. Printing the names of the sign ranges is independent of option A. Printing other exclusive bounds would produce types that cannot be written back.
- Whether option C is a PHPDoc rule of its own (it is independent of A and B), and at which level.
- Which names option D adds, given that
INFis part of the unbounded sign types.
C and the naming part of B do not depend on A, so I can send those as PRs first if that fits.
- Linguagem predominante
- PHP
- Estrelas
- 14.2k
- Forks
- 972
- Merge médio
- 13h 25min
- PRs com merge (30d)
- 142
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de phpstan/phpstan
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
Mantenedores costumam responder em até 1 dia
-
Variable in declare() {} block seems not to be considered usedTalvez já em andamento @phpstan-bot assumiu há 32 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
phpstan/phpstan#15394 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
parallel.loadLimit never reads the system load averageTalvez já em andamento @midhunmonachan assumiu há 60 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
phpstan/phpstan#15241 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
phpstan/phpstan#14597 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
Todas as issues de phpstan/phpstan
Issues semelhantes
-
bug needs grooming
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
phpstan/phpstan-phpunit#361 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
HE-Arc/le-panier-du-coin#49 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
Mantenedores costumam responder em até 2 dias
-
15.0
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100