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

Cryptic error message when using psalm-type ... it is not transparent what is actually wrong #8034

Closed
torian257x opened this issue May 31, 2022 · 4 comments
Labels

Comments

@torian257x
Copy link

torian257x commented May 31, 2022

Can you quickly point out what is wrong in the array I return?

I cannot. This is saddening tbh.... it should be fairly easy to point the first place where an inconsistency happens, no? instead of just spitting the monster of the entire definition plus the data and go "well lmao, figure out yourself what is wrong"

Target PHP version: 8.1 (inferred from current PHP version)
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░

ERROR: InvalidReturnType - symfony/tests/Classes/TestDevJobService.php:27:20 - The declared return type 'array<array-key, array{_id: string, activeFrom: string, actualCity: string, address: string, annualSalaryFrom: int, annualSalaryTo: int, candidateContactWay: string, cityCategory: string, company: string, companyId: string, companySize: string, companyType: string, country: "ch"|"de", expLevel: string, expiresOn: null|string, hasVisaSponsorship: string, isFullRemote: bool, jobType: string, jobUrl: string, language: string, latitude: float, logoImg: string, longitude: float, name: string, offerStockOrBonus: bool, postalCode: string, techCategory: string, technologies: array<int, string>}>' for App\Tests\Classes\TestDevJobService::getApiJobs is incorrect, got 'array{array{_id: "asdfas123123", activeFrom: "2022-04-16T00:00:00.000+02:00", actualCity: "Aachen", address: "elefantenstrasse 12", annualSalaryFrom: 55000, annualSalaryTo: 70000, candidateContactWay: "Email", cityCategory: "Aachen", company: "bkip ebus solutions GmbH", companyId: "623b3be0c421b2d41d3778db", companySize: "<50", companyType: "Startup", expLevel: "Senior", expiresOn: null, hasVisaSponsorship: "No", isFullRemote: false, jobType: "Full-Time", jobUrl: "bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt", language: "English", latitude: float(50.76881525), logoImg: "bkip-ebus-solutions-gmbh-logo.jpg", longitude: float(6.08364339), name: "Software-Architekten (m/w/d) für Elektromobilität", offerStockOrBonus: false, postalCode: "52064", techCategory: "Architect", technologies: array{"Angular", "CI/CD", "DevOps", "Docker", "ElasticSearch", "Git", "JBoss", "Java", "Jenkins", "Quarkus"}}}' (see https://psalm.dev/011)
   * @psalm-return APIResponse


ERROR: InvalidReturnStatement - symfony/tests/Classes/TestDevJobService.php:32:12 - The inferred type 'array{array{_id: "asdfas123123", activeFrom: "2022-04-16T00:00:00.000+02:00", actualCity: "Aachen", address: "elefantenstrasse 12", annualSalaryFrom: 55000, annualSalaryTo: 70000, candidateContactWay: "Email", cityCategory: "Aachen", company: "bkip ebus solutions GmbH", companyId: "623b3be0c421b2d41d3778db", companySize: "<50", companyType: "Startup", expLevel: "Senior", expiresOn: null, hasVisaSponsorship: "No", isFullRemote: false, jobType: "Full-Time", jobUrl: "bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt", language: "English", latitude: float(50.76881525), logoImg: "bkip-ebus-solutions-gmbh-logo.jpg", longitude: float(6.08364339), name: "Software-Architekten (m/w/d) für Elektromobilität", offerStockOrBonus: false, postalCode: "52064", techCategory: "Architect", technologies: array{"Angular", "CI/CD", "DevOps", "Docker", "ElasticSearch", "Git", "JBoss", "Java", "Jenkins", "Quarkus"}}}' does not match the declared return type 'array<array-key, array{_id: string, activeFrom: string, actualCity: string, address: string, annualSalaryFrom: int, annualSalaryTo: int, candidateContactWay: string, cityCategory: string, company: string, companyId: string, companySize: string, companyType: string, country: "ch"|"de", expLevel: string, expiresOn: null|string, hasVisaSponsorship: string, isFullRemote: bool, jobType: string, jobUrl: string, language: string, latitude: float, logoImg: string, longitude: float, name: string, offerStockOrBonus: bool, postalCode: string, techCategory: string, technologies: array<int, string>}>' for App\Tests\Classes\TestDevJobService::getApiJobs (see https://psalm.dev/128)
    return [
        [
            '_id' => 'asdfas123123',
            'jobUrl' => 'bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt',
            'isFullRemote' => false,
            'companyId' => '623b3be0c421b2d41d3778db',
            'longitude' => 6.08364339,
            'latitude' => 50.76881525,
            'cityCategory' => 'Aachen',
            'logoImg' => 'bkip-ebus-solutions-gmbh-logo.jpg',
            'activeFrom' => '2022-04-16T00:00:00.000+02:00',
            'expiresOn' => NULL,
            'candidateContactWay' => 'Email',
            'company' => 'bkip ebus solutions GmbH',
            'address' => 'elefantenstrasse 12',
            'actualCity' => 'Aachen',
            'postalCode' => '52064',
            'companyType' => 'Startup',
            'companySize' => '<50',
            'hasVisaSponsorship' => 'No',
            'language' => 'English',
            'offerStockOrBonus' => false,
            'name' => 'Software-Architekten (m/w/d) für Elektromobilität',
            'jobType' => 'Full-Time',
            'expLevel' => 'Senior',
            'annualSalaryFrom' => 55000,
            'annualSalaryTo' => 70000,
            'techCategory' => 'Architect',
            'technologies' => array (0 => 'Angular', 1 => 'CI/CD', 2 => 'DevOps', 3 => 'Docker', 4 => 'ElasticSearch', 5 => 'Git', 6 => 'JBoss', 7 => 'Java', 8 => 'Jenkins', 9 => 'Quarkus',),

        ]
    ];

@torian257x
Copy link
Author

yes, reproduceable here: https://psalm.dev/r/d733c3320d

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d733c3320d
<?php

class Test{
/**
 * @psalm-type APIResponse = array<array{
 *      _id: string,
 *      jobUrl: string,
 *      isFullRemote: bool,
 *      companyId: string,
 *      longitude: float,
 *      latitude: float,
 *      cityCategory: string,
 *      logoImg: string,
 *      activeFrom: string,
 *      expiresOn: ?string,
 *      candidateContactWay: string,
 *      company: string,
 *      address: string,
 *      actualCity: string,
 *      postalCode: string,
 *      companyType: string,
 *      companySize: string,
 *      hasVisaSponsorship: string,
 *      language: string,
 *      offerStockOrBonus: bool,
 *      name: string,
 *      jobType: string,
 *      expLevel: string,
 *      annualSalaryFrom: int,
 *      annualSalaryTo: int,
 *      techCategory: string,
 *      technologies: array<int, string>,
 *      country: "de"|"ch",
 * }>
 * @psalm-return APIResponse
 */
  public function getApiJobs(): array
  {

    return [
        [
        '_id' => '6259381a37d1f57503ca646f',
        'jobUrl' => 'bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt',
        'isFullRemote' => false,
        'companyId' => '623b3be0c421b2d41d3778db',
        'longitude' => 6.08364339,
        'latitude' => 50.76881525,
        'cityCategory' => 'Aachen',
        'logoImg' => 'bkip-ebus-solutions-gmbh-logo.jpg',
        'activeFrom' => '2022-04-16T00:00:00.000+02:00',
        'expiresOn' => NULL,
        'candidateContactWay' => 'Email',
        'company' => 'bkip ebus solutions GmbH',
        'address' => 'elefantenstrasse 12',
        'actualCity' => 'Aachen',
        'postalCode' => '52064',
        'companyType' => 'Startup',
        'companySize' => '<50',
        'hasVisaSponsorship' => 'No',
        'language' => 'English',
        'offerStockOrBonus' => false,
        'name' => 'Software-Architekten (m/w/d) für Elektromobilität',
        'jobType' => 'Full-Time',
        'expLevel' => 'Senior',
        'annualSalaryFrom' => 55000,
        'annualSalaryTo' => 70000,
        'techCategory' => 'Architect',
        'technologies' => array (0 => 'Angular', 1 => 'CI/CD', 2 => 'DevOps', 3 => 'Docker', 4 => 'ElasticSearch', 5 => 'Git', 6 => 'JBoss', 7 => 'Java', 8 => 'Jenkins', 9 => 'Quarkus',),

        ]
    ];
        //'perkKeys' => array (0 => 'flexiblework', 1 => 'hardware', 2 => 'hybridwork', 3 => 'startupculture', 4 => 'parttime', 5 => 'coworkshops', 6 => 'teamevents', 7 => 'tablefoot', 8 => 'standingdesk', 9 => 'sweets', 10 => 'coffee', 11 => 'intteam', 12 => 'coparking', 13 => 'beer', 14 => 'cooloffice',),
       //'filterTags' => array (0 => 'Atlassian', 1 => 'BitBucket', 2 => 'Confluence', 3 => 'DevOps', 4 => 'Docker', 5 => 'ElasticSearch', 6 => 'JBoss', 7 => 'JIRA', 8 => 'Java', 9 => 'Jenkins', 10 => 'Python', 11 => 'REST', 12 => 'Angular', 13 => 'CI/CD', 14 => 'Git', 15 => 'Quarkus',),
  }
}
Psalm output (using commit 3a24488):

ERROR: InvalidReturnStatement - 40:12 - The inferred type 'array{array{_id: '6259381a37d1f57503ca646f', activeFrom: '2022-04-16T00:00:00.000+02:00', actualCity: 'Aachen', address: 'elefantenstrasse 12', annualSalaryFrom: 55000, annualSalaryTo: 70000, candidateContactWay: 'Email', cityCategory: 'Aachen', company: 'bkip ebus solutions GmbH', companyId: '623b3be0c421b2d41d3778db', companySize: '<50', companyType: 'Startup', expLevel: 'Senior', expiresOn: null, hasVisaSponsorship: 'No', isFullRemote: false, jobType: 'Full-Time', jobUrl: 'bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt', language: 'English', latitude: float(50.76881525), logoImg: 'bkip-ebus-solutions-gmbh-logo.jpg', longitude: float(6.08364339), name: 'Software-Architekten (m/w/d) für Elektromobilität', offerStockOrBonus: false, postalCode: '52064', techCategory: 'Architect', technologies: array{'Angular', 'CI/CD', 'DevOps', 'Docker', 'ElasticSearch', 'Git', 'JBoss', 'Java', 'Jenkins', 'Quarkus'}}}' does not match the declared return type 'array<array-key, array{_id: string, activeFrom: string, actualCity: string, address: string, annualSalaryFrom: int, annualSalaryTo: int, candidateContactWay: string, cityCategory: string, company: string, companyId: string, companySize: string, companyType: string, country: 'ch'|'de', expLevel: string, expiresOn: null|string, hasVisaSponsorship: string, isFullRemote: bool, jobType: string, jobUrl: string, language: string, latitude: float, logoImg: string, longitude: float, name: string, offerStockOrBonus: bool, postalCode: string, techCategory: string, technologies: array<int, string>}>' for Test::getApiJobs

ERROR: InvalidReturnType - 35:18 - The declared return type 'array<array-key, array{_id: string, activeFrom: string, actualCity: string, address: string, annualSalaryFrom: int, annualSalaryTo: int, candidateContactWay: string, cityCategory: string, company: string, companyId: string, companySize: string, companyType: string, country: 'ch'|'de', expLevel: string, expiresOn: null|string, hasVisaSponsorship: string, isFullRemote: bool, jobType: string, jobUrl: string, language: string, latitude: float, logoImg: string, longitude: float, name: string, offerStockOrBonus: bool, postalCode: string, techCategory: string, technologies: array<int, string>}>' for Test::getApiJobs is incorrect, got 'array{array{_id: '6259381a37d1f57503ca646f', activeFrom: '2022-04-16T00:00:00.000+02:00', actualCity: 'Aachen', address: 'elefantenstrasse 12', annualSalaryFrom: 55000, annualSalaryTo: 70000, candidateContactWay: 'Email', cityCategory: 'Aachen', company: 'bkip ebus solutions GmbH', companyId: '623b3be0c421b2d41d3778db', companySize: '<50', companyType: 'Startup', expLevel: 'Senior', expiresOn: null, hasVisaSponsorship: 'No', isFullRemote: false, jobType: 'Full-Time', jobUrl: 'bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt', language: 'English', latitude: float(50.76881525), logoImg: 'bkip-ebus-solutions-gmbh-logo.jpg', longitude: float(6.08364339), name: 'Software-Architekten (m/w/d) für Elektromobilität', offerStockOrBonus: false, postalCode: '52064', techCategory: 'Architect', technologies: array{'Angular', 'CI/CD', 'DevOps', 'Docker', 'ElasticSearch', 'Git', 'JBoss', 'Java', 'Jenkins', 'Quarkus'}}}'

@AndrolGenhald
Copy link
Collaborator

You have no "country" key: https://psalm.dev/r/342ae3fb2b

You can figure this out by removing keys from the definition one by one. There is some ongoing effort to improve this in #7445 and #7890.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/342ae3fb2b
<?php

class Test{
/**
 * @psalm-type APIResponse = array<array{
 *      _id: string,
 *      jobUrl: string,
 *      isFullRemote: bool,
 *      companyId: string,
 *      longitude: float,
 *      latitude: float,
 *      cityCategory: string,
 *      logoImg: string,
 *      activeFrom: string,
 *      expiresOn: ?string,
 *      candidateContactWay: string,
 *      company: string,
 *      address: string,
 *      actualCity: string,
 *      postalCode: string,
 *      companyType: string,
 *      companySize: string,
 *      hasVisaSponsorship: string,
 *      language: string,
 *      offerStockOrBonus: bool,
 *      name: string,
 *      jobType: string,
 *      expLevel: string,
 *      annualSalaryFrom: int,
 *      annualSalaryTo: int,
 *      techCategory: string,
 *      technologies: array<int, string>,
 * }>
 * @psalm-return APIResponse
 */
  public function getApiJobs(): array
  {

    return [
        [
        '_id' => '6259381a37d1f57503ca646f',
        'jobUrl' => 'bippokippo-solutions-Architekten-mwd-fr-Elektromobilitt',
        'isFullRemote' => false,
        'companyId' => '623b3be0c421b2d41d3778db',
        'longitude' => 6.08364339,
        'latitude' => 50.76881525,
        'cityCategory' => 'Aachen',
        'logoImg' => 'bkip-ebus-solutions-gmbh-logo.jpg',
        'activeFrom' => '2022-04-16T00:00:00.000+02:00',
        'expiresOn' => NULL,
        'candidateContactWay' => 'Email',
        'company' => 'bkip ebus solutions GmbH',
        'address' => 'elefantenstrasse 12',
        'actualCity' => 'Aachen',
        'postalCode' => '52064',
        'companyType' => 'Startup',
        'companySize' => '<50',
        'hasVisaSponsorship' => 'No',
        'language' => 'English',
        'offerStockOrBonus' => false,
        'name' => 'Software-Architekten (m/w/d) für Elektromobilität',
        'jobType' => 'Full-Time',
        'expLevel' => 'Senior',
        'annualSalaryFrom' => 55000,
        'annualSalaryTo' => 70000,
        'techCategory' => 'Architect',
        'technologies' => array (0 => 'Angular', 1 => 'CI/CD', 2 => 'DevOps', 3 => 'Docker', 4 => 'ElasticSearch', 5 => 'Git', 6 => 'JBoss', 7 => 'Java', 8 => 'Jenkins', 9 => 'Quarkus',),

        ]
    ];
        //'perkKeys' => array (0 => 'flexiblework', 1 => 'hardware', 2 => 'hybridwork', 3 => 'startupculture', 4 => 'parttime', 5 => 'coworkshops', 6 => 'teamevents', 7 => 'tablefoot', 8 => 'standingdesk', 9 => 'sweets', 10 => 'coffee', 11 => 'intteam', 12 => 'coparking', 13 => 'beer', 14 => 'cooloffice',),
       //'filterTags' => array (0 => 'Atlassian', 1 => 'BitBucket', 2 => 'Confluence', 3 => 'DevOps', 4 => 'Docker', 5 => 'ElasticSearch', 6 => 'JBoss', 7 => 'JIRA', 8 => 'Java', 9 => 'Jenkins', 10 => 'Python', 11 => 'REST', 12 => 'Angular', 13 => 'CI/CD', 14 => 'Git', 15 => 'Quarkus',),
  }
}
Psalm output (using commit 3a24488):

No issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants