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
Type of global constant from define() #2644
Comments
Does psalm stop complaining if you remove the |
Psalm continues to give errors about the undefined constant.
I changed <?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="public"/>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<globals>
<var name="app" type="Slim\App"/>
</globals>
</psalm> I'm probably going to use a baseline file and run with --show-info=false, but I'd love to have some way to say |
The problem with I think I was able to reproduce your issue here (omitting Slim dependencies): https://github.com/weirdan/psalm-issue-variable-constant/commits/master. See the commit / build history, this change fixes the issue: https://github.com/weirdan/psalm-issue-variable-constant/commit/92e314964b99bbc31362c2235d2f41bbe11c886c This feels like a hack to me though. @muglug what do you think? Should there be a config section listing the files to analyze before continuing with those listed in |
This is the appropriate way to define constants for Psalm, but maybe there should be an extra flag for constants defined using I don't want to throw out string values of |
I fixed the issue that @weirdan isolated – I hope that should be enough. |
I can confirm the It turned out, there is weirdness that probably only affects me: we actually got this app from a consulting team, who decided to put the config dir below I moved |
I have a Slim Framework app I'm adding Psalm to. There is a global constant defined at runtime during configuration:
This constant is not available when Psalm is running, because it doesn't load in via the framework's front controller. If I give Psalm a bootstrap file that defines the constant, then Psalm ends up thinking the constant can have only one value, and flags the other values as impossible. (Psalm is set up to analyze this settings file, since it's under src/ with everything else, but it doesn't seem to be picking up this information about the constant and applying it to other files. Which is reasonable, since Psalm doesn't know the entry points / load order.)
Maybe the type could be set in
<globals>
in the config, except that it's not a variable, so that didn't work. It doesn't look like globals supports a const/constant tag.It seems to be too complex to reproduce on https://psalm.dev – if everything is in one file, then Psalm can recognize that the constant can have multiple values and reports "no issues".
How do I get the correct type, or even just
string
, to Psalm; or, should I replace the constant with a global variable?vimeo/psalm 3.8.2.
The text was updated successfully, but these errors were encountered: