Skip to content

Assigning to a variable before use in a conditional #3869

Answered by B-rando1
NoahCardoso asked this question in Q&A
Discussion options

You must be logged in to vote

I've looked a few times at this. If we want to create the variable directly above the if-statement, this function is the place that makes the most sense to me. Because it returns a list of statements, it would be difficult to insert the varDecDefs after this point.

I'm not exactly sure how it'll work with the types, but roughly what I think we need to do is modify the function like this:

chooseConstr :: (OOProg r) => ConstraintBehaviour ->
  [(CodeVarChunk, [ConstraintCE])] -> GenState [MSStatement r]
chooseConstr cb cs = do
  varDefs <- mapM constrVarDef cs -- constrVarDef needs to act like `constrWarn` to generate either an `emptyStmt` or a `varDecDef`, depending on constraint type
  co…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@NoahCardoso
Comment options

NoahCardoso Jul 24, 2024
Collaborator Author

Answer selected by balacij
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants