Skip to content

Properties called directly on @(Array) declaration not scoped. #146

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

Open
DarkLite1 opened this issue Sep 12, 2018 · 7 comments
Open

Properties called directly on @(Array) declaration not scoped. #146

DarkLite1 opened this issue Sep 12, 2018 · 7 comments

Comments

@DarkLite1
Copy link

Methods look like a string when called between $():

image

Version: 1.28.0-insider (user setup)
Commit: ee6a21fa49bd1906bd1378c2f2714cd656409e5c
Date: 2018-09-11T05:18:39.589Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64
@DarkLite1
Copy link
Author

From #1522

@PwshPally
Copy link

This is the same as issue #141.

Unfortunately I don't know how to combine them nor if I should.

@TylerLeonhardt
Copy link
Member

Thanks for that @PSPally. I'll close this as a dupe of #141.

@omniomi
Copy link
Contributor

omniomi commented Sep 13, 2018

So, this is less that properties/methods within a sub-expression are incorrect and more that we didn't account for people calling methods on an array declaration.

subexpression

Now, your syntax is valid so I'll work on getting that added at some point; However, is there a reason for doing it that way in your code instead of just using $($ImportedMatrix.Count) or if $ImportedMatrix is not already an array coercing it before the hashtable? You'd be able to work around this for now if so:

PS C:\> $Array = 1..10
PS C:\> "$(@($Array).Count) Blah"
10 Blah

PS C:\> "$($Array.Count) Blah"
10 Blah

@DarkLite1
Copy link
Author

Thanks for looking at this @omniomi . The reason is indeed that we're not certain that $ImportedMatrix has values in it so we cast it to an array to be sure we can use the count method.

@omniomi omniomi changed the title Color incorrect Properties called directly on @(Array) declaration not scoped. Sep 13, 2018
@msftrncs
Copy link
Contributor

A quick correction, (noting that static members are allowed here too). (I might be using a different scope for the member here than the regular syntax is using)

For the end of the array definition:

			"end": "(\\))((?:(?:\\.|::)(?:\\p{L}|\\d|_)+)*\\b)?",
			"endCaptures": {
				"1": {
					"name": "punctuation.section.group.end.powershell"
				},
				"2": {
					"name": "variable.other.member.powershell"
				}
			},

It also turns out that this can work for Hash table definitions as well:

@{name="bob";age=42}.count

@msftrncs
Copy link
Contributor

Add scriptblocks to the list of items that should have member access scoped, not a common item by any means, as I am not sure it has any practical uses in a script file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants