-
Notifications
You must be signed in to change notification settings - Fork 676
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
LINQ immediate query execution not caught for type checking #1244
Comments
|
This is an expected error. |
@DustinCampbell I think that having @duraz0rz |
Why would this be flagged? |
OK. |
To be clear, this is how the C# language works. I get exactly the same error with |
No, I also think C# works correctly. And it's not the same error. VS Code has no error hinted at line 13, while the compiler points it there. VS Code hints an error at line 14, I'm talking about the squiggly red line. |
Well, there isn't error on line 13 and the compiler doesn't point there. Here's what I get with
|
Well, there is: EDIT: And yes, you are right. |
Sorry, but that didn't make sense to me. The expression You mentioned that you see a different error from the C# compiler than you do in VS Code, correct? Could you provide the error that you're getting from the compiler? |
No, I was wrong about that, the compiler and VS Code both point to the same spot. You were correct in closing the issue. The problem I see is |
I see where the confusion is now -- thanks! Unfortunately, |
I'm not sure what you might be There are a couple of fixes I could imagine. Here's a couple:
var fib2 = fib.Where(x => x > 2).ToArray();
Console.WriteLine($"{ fib2[0] }");
var fib2 = fib.Where(x => x > 2);
Console.WriteLine($"{ fib2.First() }"); |
It does have an effect. The problem is that you immediately converted it to an |
I was under the impression that final |
Please refer to the C# specification: https://github.com/dotnet/csharplang/blob/master/spec/expressions.md#simple-assignment. The important bit is here:
It's that last bullet that's critical here.
Essentially, this is doing exactly what your code is telling it to do. |
I opened an issue on csharplang as you suggested. My opinion is that the behavior of implicit conversion through assignment is not optimal in this case. A pretty big gotcha for me. I was expecting an error like "you can't assign yada yada", if array operations are not possible on the query result, no matter how legal the conversion. |
Just to set expectations, I wouldn't expect this to go very far. This is how the language (and other languages like C and Java) have worked for years. Changing this behavior would be a major breaking change. |
I can live with that. It's been a learning experience. Thank you 👍 |
No problem! |
Environment data
dotnet --info
output:.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
VS Code version:
Version 1.9.1
Commit f9d0c687ff2ea7aabd85fb9a43129117c0ecf519
Date 2017-02-08T23:44:55.542Z
Shell 1.4.6
Renderer 53.0.2785.143
Node 6.5.0
C# Extension version:
1.7.0
Steps to reproduce
Make a LINQ interrogation over a array, using an immediate query execution operator: ToArray
Expected behavior
Catch type changing from collection to array here:
IEnumerable<int> fib2 = fib.Where(x => x > 2).ToArray();
.Actual behavior
Catches type change here:
Console.WriteLine($"{fib2[0]");
.The text was updated successfully, but these errors were encountered: