PowerShell / PowerShell/DSC

Lambda variables in `map()` function cannot be used as arguments to nested function calls

Open
#1,231 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Need-Review
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Summary

I am experiencing a problem with using lambda variables from map() function as arguments to nested function calls in DSC expressions whilst working on #1230.

Steps to reproduce
  1. Create a DSC configuration with a map() expression that uses a lambda variable
  2. Pass the lambda variable as an argument to a function within the map body
  3. Execute the configuration

Example config:

$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
parameters:
  baseNetwork:
    type: string
    defaultValue: 10.144.0.0/20
  newPrefix:
    type: int
    defaultValue: 24
  subnetCount:
    type: int
    defaultValue: 5
resources:
  - name: Generate subnets
    type: Microsoft.DSC.Debug/Echo
    properties:
      output: "[map(range(0, parameters('subnetCount')), 'i', cidrSubnet(parameters('baseNetwork'), parameters('newPrefix'), i))]"
Expected behavior
The `map()` function should iterate over the range [0, 1, 2, 3, 4], pass each value as the lambda variable i, and successfully call `cidrSubnet()` with that variable as the third argument. The output should be an array of 5 subnet CIDR strings.
Actual behavior
ERROR Parser: Found error node parsing function
Error details

Environment data
Name                           Value
----                           -----
PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Version

dsc 3.2.0-preview.7

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the DSC configuration using map(), range(), and cidrSubnet() from the issue, then trace the expression parser where the nested function call reports an error node. Check how the map lambda variable is passed into function arguments. Done means the configuration executes successfully and produces an array of five subnet CIDR strings.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.