Sourcery icon indicating copy to clipboard operation
Sourcery copied to clipboard

'Any' Type Issue

Open pavel-trafimuk opened this issue 7 months ago • 0 comments

After updating Sourcery to new version, I found that one of my template is failing I found commit which broke it: 7153768c655c5e2435323cd08f01ed8b2d13f765 https://github.com/krzysztofzablocki/Sourcery/pull/1345

Part of the template: {% for decodeType in types.all where decodeType.directory|contains:argument.targetName and (decodeType.kind == "struct" or decodeType.kind == "class") and (decodeType|based:"Codable" or decodeType|based:"Decodable" ) and decodeType.annotations.DISABLED_FAILED_TESTS == nil %}

Zrzut ekranu 2024-07-16 o 14 23 42

As I understand the problem, @art-divin you added new type 'Any', but which does not support some properties, like directory which is nil and filtering of nil throws the error: decodeType.directory|contains:argument.targetName

I don't know if it's really issue or WAD, anyway my local fix is to check kind for 'struct+class' earlier than directory, but maybe we should have some guards, e.g. resolving filter of nil should return nil earlier without deep diving and throwing the error

Zrzut ekranu 2024-07-17 o 11 10 27

as you see, result is already nil, I don't see any reasons trying to filter it

WDYT about it

pavel-trafimuk avatar Jul 17 '24 09:07 pavel-trafimuk