Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5837865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:24:25+00:00 2026-05-22T11:24:25+00:00

The compiler complains that resultingThing in the code below is being used before being

  • 0

The compiler complains that resultingThing in the code below is being used before being assigned to.

private IEnumerable<IThing> FindThings(dynamic spec)
{
    if (spec == null)
        yield break;

    IThing resultingThing;
    if (spec.Something > 0 && dictionary.TryGetValue(spec.Something, out resultingThing))
        yield return resultingThing;
    else
        // ...
}

Why does it claim this?

I have tried a different version of the method in which there are no yield usages (e.g. just return IEnumerable<IThing>) but with the dynamic parameter, and I have tried a version of the method in which dynamic is not passed in (i.e. what we’ve done in prior versions of C#). These compile.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:24:26+00:00Added an answer on May 22, 2026 at 11:24 am

    I appears to be a compiler bug (or limitation, if you prefer).

    I reduced the minimal failing case to:

    static private IThing FindThings(dynamic spec)
    {
        IThing resultingThing;
        if ((null!=spec) && dictionary.TryGetValue(spec, out resultingThing))
            return resultingThing;
    return null;
    }
    

    Which gives the same compiler diagnostic, without involving member lookup on dynamics, nor iterator blocks.

    For reference the mono compiler does not trip over that:

    using System;
    using System.Collections.Generic;
    
    public static class X
    {
        public interface IThing { }
    
        private static readonly IDictionary<string, IThing> dictionary = new Dictionary<string, IThing>();
    
        static private IThing FindThings(dynamic spec)
        {
            IThing resultingThing;
            if ((null!=spec) && dictionary.TryGetValue(spec, out resultingThing))
                return resultingThing;
            return null;
        }
    
        public static void Main(string[] s)
        {
    
        }
    }
    

    Compiling that:

    dmcs -v -warnaserror -warn:4 t.cs
    

    No warnings

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is it that in the code below the compiler complains that PureAbstractBase is
When I compile the following code, my compiler complains that the following line is
This doesn't seem to work (compiler complains that Something 's getFoo() method doesn't implement
I have two classes that refer to each other, but obviously the compiler complains.
The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
Is the following allowed? typedef Foo<Bar> Bar; My compiler complains that 'class Bar' has
When trying to create a category for NSInteger, the compiler complains that it Cannot
I'm currently starting with Perl OOP using the Moose package. The compiler complains that
The compiler complains about this, after I activated all kind of warnings: For MyApp_Prefix.pch
g++ compiler complains about conversions between related types (from int to enum, from void*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.