Skip to content

Allow _ in use! bindings values #18487

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

Merged
merged 17 commits into from
Apr 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into fix-16343
# Conflicts:
#	src/Compiler/Checking/Expressions/CheckComputationExpressions.fs
  • Loading branch information
edgarfgp committed Apr 25, 2025
commit edb0e1aa4bb08aa3fea86dfdcbd49045f9894052
Original file line number Diff line number Diff line change
Expand Up @@ -1779,54 +1779,7 @@ let rec TryTranslateComputationExpression
|> addBindDebugPoint spBind
)

// 'let! pat = expr in expr'
// --> build.Bind(e1, (fun _argN -> match _argN with pat -> expr))
// or
// --> build.BindReturn(e1, (fun _argN -> match _argN with pat -> expr-without-return))
| SynExpr.LetOrUseBang(
bindDebugPoint = spBind
isUse = false
isFromSource = isFromSource
pat = pat
rhs = rhsExpr
andBangs = []
body = innerComp
trivia = { LetOrUseBangKeyword = mBind }) ->

if ceenv.isQuery then
error (Error(FSComp.SR.tcBindMayNotBeUsedInQueries (), mBind))

// Add the variables to the query variable space, on demand
let varSpace =
addVarsToVarSpace varSpace (fun _mCustomOp env ->
use _holder = TemporarilySuspendReportingTypecheckResultsToSink cenv.tcSink

let _, _, vspecs, envinner, _ =
TcMatchPattern cenv (NewInferenceType cenv.g) env ceenv.tpenv pat None TcTrueMatchClause.No

vspecs, envinner)

let rhsExpr =
mkSourceExprConditional isFromSource rhsExpr ceenv.sourceMethInfo ceenv.builderValName

Some(
TranslateComputationExpressionBind
ceenv
comp
q
varSpace
mBind
(addBindDebugPoint spBind)
"Bind"
[ rhsExpr ]
pat
innerComp
translatedCtxt
)

// 'use! pat = e1 in e2' --> build.Bind(e1, (function _argN -> match _argN with pat -> build.Using(x, (fun _argN -> match _argN with pat -> e2))))
// or
// 'use! _ = e1 in e2' --> build.Bind(e1, (fun _argN -> e2))
// 'use! pat = e1 in e2' --> build.Bind(e1, (function _argN -> match _argN with pat -> build.Using(x, (fun _argN -> match _argN with pat -> e2))))
| ExprAsUseBang(spBind, isFromSource, pat, rhsExpr, andBangs, innerComp, mBind) ->
if ceenv.isQuery then
error (Error(FSComp.SR.tcBindMayNotBeUsedInQueries (), mBind))
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.