-
Notifications
You must be signed in to change notification settings - Fork 440
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
chore: Enable type coercion again #2750
Conversation
a1af449
to
e6f584e
Compare
nodeIds, | ||
scopedIds | ||
); | ||
// const references = await extractReferencesFromExpression( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These get removed in the iterators PR I believe.
@@ -551,11 +565,128 @@ function convertTFExpressionAstToTs( | |||
return t.stringLiteral(""); | |||
} | |||
|
|||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is moved from generation.ts
return "dynamic"; | ||
} | ||
|
||
export function findExpressionType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is mostly a copy of the generation.ts one, but doesn't use references, and does more smart things :D
Signed-off-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
This reverts commit 040b790.
e6f584e
to
3f6550f
Compare
if (mapping.parameters.length > 0 && mapping.parameters[0].variadic) { | ||
return t.callExpression(callee, [ | ||
t.arrayExpression( | ||
argumentExpressions.map((argExpr) => | ||
coerceType( | ||
scope, | ||
argExpr, | ||
findExpressionType(scope, argExpr), | ||
mapping.parameters[0].type | ||
) | ||
) | ||
), | ||
]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also possible that e.g. the second parameter of two is variadic (e.g. cidrsubnets
) – which would not be caught by this.
An alternative would be to remove this map
and extend the one below to handle the (if any) variadic parameter. I did this in my prototyped code here:
terraform-cdk/packages/@cdktf/hcl2cdk/lib/__tests__/functions.test.ts
Lines 692 to 717 in 7793f56
const args: t.Expression[] = []; | |
mapping.parameters.forEach((param, idx) => { | |
if (param.variadic) { | |
// return an array with all remaining children (each mapped accordingly) | |
args.push( | |
t.arrayExpression( | |
tfAst.children | |
.slice(idx) | |
.map((child) => terraformThingToTs(child, param.type)) | |
) | |
); | |
} else { | |
const child = tfAst.children[idx]; | |
if (child) { | |
args.push(terraformThingToTs(child, param.type)); | |
} else if (!param.optional) { | |
throw new Error( | |
`Terraform function call to "${name}" is not valid! Parameter at index ${idx} of type ${ | |
param.type | |
} is not optional but received no value. The following parameters were passed: ${JSON.stringify( | |
tfAst.children | |
)}` | |
); | |
} | |
} | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in: #2833
I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Related issue
Fixes #
Description
In plain English, describe your approach to addressing the issue linked above. For example, if you made a particular design decision, let us know why you chose this path instead of another solution.
Checklist