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

A value of type X cannot be used to initialize an entity of type X #3212

Closed
Leedehai opened this issue Feb 25, 2019 · 19 comments
Closed

A value of type X cannot be used to initialize an entity of type X #3212

Leedehai opened this issue Feb 25, 2019 · 19 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@Leedehai
Copy link

Leedehai commented Feb 25, 2019

Type: LanguageService

Describe the bug

  • OS and Version: macOS 10.14.3
  • VS Code Version: 1.13.1
  • C/C++ Extension Version: 0.21.0
  • Other extensions you installed (and if the issue persists after disabling them): too many... yes
  • A clear and concise description of what the bug is: A value of type X cannot be used to initialize an entity of type X

To Reproduce

  1. Create a new document, select the language to be "C++", and type:
struct Value {
    struct Array;
    struct Dict;
    struct Primitive;

    Value() {}
    virtual ~Value() {}

    virtual Array * asArray() { assert(false); }
    virtual Dict * asDict() { assert(false); }
    virtual Primitive * asPrimitive() { assert(false); }

    int asInt();
    double asDouble();
    std::string asDate();
    std::string asString();
};

struct Value::Array : public Value {

    Array() {}
    ~Array() {}

    Value::Array * asArray() { 
        Value::Array * result = this; 
        return result;
    }
};
  1. Wait for the IntelliSence's error squiggle and message (shown in screenshot).

Expected behavior

This is a legitimate assignment and there should not be an error.

Screenshots
screen shot 2019-02-24 at 23 38 36

other info:
Might related to this on StackOverflow, though it's not clear whether the problem described in that post occurred in VSCode or other IDE/editor.

@Leedehai
Copy link
Author

However, this is in a .h file. Moving the definition of asArray() to another .cpp file solves the issue.
screen shot 2019-02-24 at 23 44 37

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Feb 25, 2019

I'm able to repro the bug. It's a bug inherited from VS. I normally would create a bug on VS myself, but they've asked us to have users to report it themselves at https://developercommunity.visualstudio.com/content/problem/post.html?space=62 -- simply pasting a link to this bug report would be good enough. If that is too much of a burden for you, let me know, and I'll open the bug myself.

@sean-mcmanus sean-mcmanus added bug Language Service Visual Studio Inherited from Visual Studio labels Feb 25, 2019
@Leedehai
Copy link
Author

@sean-mcmanus hi thanks for your feedback! However it requires an MS account but I don't have one and don't intend to create one at the moment...

@sean-mcmanus
Copy link
Collaborator

If you click the "Sign-in options" you should be able to login using your GitHub account.

image

@sean-mcmanus
Copy link
Collaborator

I filed a VS bug https://developercommunity.visualstudio.com/content/problem/471939/c-intellisense-incorrectly-show-a-value-of-type-x.html . But it sounds like they want more upvotes before they'll fix it.

@sean-mcmanus
Copy link
Collaborator

Looks like this was already reported in July (from the Stack Overflow): https://developercommunity.visualstudio.com/content/problem/293884/e0144-being-reported-for-valid-code-intellisense-e.html . It needs more upvotes.

@Colengms Colengms added this to the Tracking milestone Oct 10, 2019
@Colengms Colengms added the more votes needed Issues that have been postponed until more community members upvote it label Oct 14, 2019
@stcheng
Copy link

stcheng commented Apr 25, 2020

encountered the same issue

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Apr 25, 2020

@stcheng Are you able to upvote the VS issue at https://developercommunity.visualstudio.com/content/problem/293884/e0144-being-reported-for-valid-code-intellisense-e.html ? Or if enough people can upvote this GitHub issue we may be able to get them to re-open it.

@matjam
Copy link

matjam commented Jun 5, 2020

Just hit this myself.

@jmspit
Copy link

jmspit commented Sep 4, 2020

Annoying problem - please fix.

@sean-mcmanus
Copy link
Collaborator

To suppress this error, you can add

#if __INTELLISENSE__
#pragma diag_suppress 144
#endif

to some code in the TU, such as in a forcedInclude:

            "forcedInclude": [
                "${workspaceFolder}/ingoreIntelliSenseErrors.h"
            ]

Starting with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders4, the error codes are added to the IntelliSense errors, so other invalid errors can be suppressed as well.

@bobpaw
Copy link

bobpaw commented Jan 14, 2021

Still seeing this same error, in addition to error 513 which is the same but states, "a value of type X cannot be assigned to an entity of type X".

@HermanEldering
Copy link

Are you able to upvote the VS issue at https://developercommunity.visualstudio.com/content/problem/293884/e0144-being-reported-for-valid-code-intellisense-e.html ? Or if enough people can upvote this GitHub issue we may be able to get them to re-open it.

@sean-mcmanus They have closed the issue, which also blocks voting and commenting on the issue. I really dislike developercommunity.visualstudio.com, it feels futile to report issues. It used to be better in the past (when they used Connect).

@sean-mcmanus
Copy link
Collaborator

@HermanEldering I have re-activated the internal ticket so you can upvote now -- looks like the issue got mistakenly dup'd to a different issue with the same error message involving enums.

@vaggelanos
Copy link

Same behavior on VS 2019 latest version.

static struct PhysicalDeviceProperties
{
	VkSurfaceFormatKHR* supportedSurfacesFormats;
	VkPresentModeKHR* supportedPresentModes;
} m_physicalDeviceProperties;
struct PhysicalDeviceProperties deviceSupportedProperties = {
			.supportedPresentModes = VK_NULL_HANDLE,
			.supportedSurfacesFormats = VK_NULL_HANDLE
		};

m_physicalDeviceProperties = deviceSupportedProperties;

Error (active) E0513 a value of type "struct PhysicalDeviceProperties" cannot be assigned to an entity of type "struct PhysicalDeviceProperties"

@antisocrates
Copy link

This needs to be fixed ASAP.

@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.4.0 Apr 12, 2021
@sean-mcmanus sean-mcmanus added fixed Check the Milestone for the release in which the fix is or will be available. and removed more votes needed Issues that have been postponed until more community members upvote it labels Apr 12, 2021
@sean-mcmanus
Copy link
Collaborator

@vaggelanos @antisocrates It should be fixed after we update our VS parser for 1.4.0-insiders (no date available yet).

@sean-mcmanus
Copy link
Collaborator

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.4.0-insiders2

@Leedehai
Copy link
Author

Super great, thanks for the works!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

10 participants