Skip to content

Invalid type 'Nette\DI\?T' when accessing Container#getByType() from DI config #274

Description

@dakur

Version: 3.0.11, bug present as of 3.0.10

Bug Description

If you use Container#getByType() inside of NEON configuration, it fails on resolving its return type – from Helpers#getReturnTypeAnnotation() it is returned Nette\DI\?T.

More generally, I believe (have not tried) accessing any class with method having generic return type will fail.

Steps To Reproduce

In nette/web-project, create this class:

namespace App;
final class FakeContainer
{
	/**
	 * copied from Container#getByType()
	 * @template T
	 * @param class-string<T> $type
	 * @return ?T
	 */
	public function getService(string $type)
	{
		return null;
	}
}

In services.neon, use it:

services:
	- App\FakeContainer::getService(HomepagePresenter::class)

image

Expected Behavior

Run, not to fail with type check.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions