You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Area-QueriesQuery expressions and library implementationBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
In query expressions, variables bound using for are not recognized as used if they are not selected, even if they are otherwise used for example in a where or a let.
Example:
// Expected: no warning// Actual: warning FS1182: The value 'x' is unused
query {for x in[1;2;3]do
where (x >2)
select 1}// Expected: no warning// Actual: warning FS1182: The value 'x' is unused
query {for x in[1;2;3]dolety= x
select y }// Expected: no warning// Actual: no warning
query {for x in[1;2;3]do
where (x >2)
select x }
Observed in VS 2022, v 17.8.4. I know I'm most probably not adding useful information. Just in case I am.
edit on 14th Nov 2025:
Observed in VS 2022, v 17.14.20, as shown here, when using linq2db :
(also see it in Insiders, as of today)
let getPackagesInJob (jobId: JobId) : EntPakke list =
let q = query {
for pakke in dbTre.Pakke do // <- FS1182 The value 'pakke' is unused / in "for pakke"
join register in dbTre.Register on (pakke.RegisterId = register.Id) // <- FS1182 The value 'register' is unused / in "join register"
where (register.JobId = jobId)
select pakke
}
q.ToListAsync().Result |> Seq.toList
Example of a query that does not provoke this problem:
let getPackage (id: PakkeId) : EntPakke option =
let q = query {
for pakke in dbTre.Pakke do
where (pakke.Id = id)
select pakke
}
q.SingleOrDefaultAsync().Result |> Option.ofObj
Area-QueriesQuery expressions and library implementationBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
Activity
dsyme commentedon May 7, 2015
Yes, I do recall this, it's good to have it recorded (and yes, this was one of the reasons /warn:1182 was made opt-in)
It is (unsurprisingly) related to the way computation expressions are de-sugared, which makes duplicates of the "x".
ImaginaryDevelopment commentedon May 22, 2015
are there any recommended work-a-rounds besides turning off 1182, or warnaserror for 1182?
latkin commentedon May 22, 2015
You can use standard convention of prefixing the identifier with _, which tells the compiler to ignore that identifier when computing 1182.
Tarmil commentedon May 23, 2015
What's interesting is that VFT does recognize them as the same identifier: F12 takes you to the
forline in all cases.8 remaining items
BentTranberg commentedon Jan 16, 2024
Observed in VS 2022, v 17.8.4. I know I'm most probably not adding useful information. Just in case I am.
edit on 14th Nov 2025:
Observed in VS 2022, v 17.14.20, as shown here, when using linq2db :
(also see it in Insiders, as of today)
Example of a query that does not provoke this problem:
Document Issue #422 (FS1182 false positive) as known limitation
Fix FS1182 false positive for query expression variables (#422)
Final sprint: validation complete, all 11 query bugs addressed
Move query FS1182 tests from warnon.fs to ComputationExpressionTests.fs
Document Issue #422 (FS1182 false positive) as known limitation
Fix FS1182 false positive for query expression variables (#422)
Final sprint: validation complete, all 11 query bugs addressed
Move query FS1182 tests from warnon.fs to ComputationExpressionTests.fs