IronLanguages / IronLanguages/ironpython3

FirstOrDefault returns lambda function on empty collections from .NET 6 and forward

Open
#1,761 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
2.8k
Forks
316
Avg merge
1d 9h
Merged PRs (30d)
1

Description

If you run
List[Object]().FirstOrDefault(lambda x: x)
after the appropriate imports the result will be something like this
<function <lambda$172> at 0x000000000000002B>
when it should be None

It does work as expected if you instead of object use another type like this
List[DateTime]().FirstOrDefault(lambda x: x)

I reproduced this in the IronPythonConsole by changing target framework to .NET 6 (same issue in .NET 7 and .NET 8)

Tested on
IronPython 3.4.1 DEBUG (3.4.1.1000) [.NETCoreApp,Version=v6.0 on .NET 6.0.25 (64-bit)] on win32

It seems like there is an explicit cast to PythonFunction when it should still be an Object
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the expression in the IronPythonConsole on .NET 6 or later, comparing ListObject.FirstOrDefault(lambda x: x) with the working DateTime case. Trace the FirstOrDefault entry point and the handling of the lambda result; done means the empty Object collection returns None rather than a Python function.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.