Skip to content
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

Tweak Nameof slightly, add GetNameof() support to more expressions #1618

Merged
merged 5 commits into from
Jan 22, 2024

Conversation

distributivgesetz
Copy link
Contributor

@distributivgesetz distributivgesetz commented Jan 10, 2024

Throwing is bad. Unwinding isn't healthy for tracking code errors. I refactored GetNameof() to return an optional string, which gets checked in the actual Nameof expression. There we can emit the error.

The arguments for GetNameof felt unnecessary since dmObject was unused, proc was used only once in Local, so I cut the arguments from the method. Let me know if I should keep it.

nameof() is also usable in constant contexts (eg. switch cases), so I added an override for TryAsConstant().

Also a few l-values didn't have any nameof support, so I added it in this PR.

@Hinaichigo Hinaichigo mentioned this pull request Jan 11, 2024
5 tasks
@Hinaichigo
Copy link
Contributor

When attempting to test this I get the following error:
C:...OpenDream\DMCompiler\DM\Expressions\Dereference.cs(295,45): error CS0246: The type or namespace name 'NotNullWhen' could not be found (are you missing a using directive or an assembly reference?)
I usually build OD using the dotnet build command, so maybe it's something that is normally included when you use an IDE like visual studio? Is there a workaround or some way to make it just werk with some kind of project setting?

DMCompiler/DM/Expressions/Builtins.cs Outdated Show resolved Hide resolved
DMCompiler/DM/Expressions/Builtins.cs Outdated Show resolved Hide resolved
DMCompiler/DM/Expressions/Builtins.cs Outdated Show resolved Hide resolved
DMCompiler/DM/Expressions/Dereference.cs Outdated Show resolved Hide resolved
DMCompiler/DM/Expressions/LValue.cs Show resolved Hide resolved
@distributivgesetz
Copy link
Contributor Author

distributivgesetz commented Jan 20, 2024

I'm going to move the eval of a name from the expression emission to the building phase, and if nothing depends on the existence of Nameof then I'm down to removing the class to return a constant string. Nameof is a pretty bare class anyways and I don't feel like its existence justifies having to include context parameters into TryAsConstant (which is why I removed the parameters from GetNameof)

@distributivgesetz
Copy link
Contributor Author

When attempting to test this I get the following error: C:...OpenDream\DMCompiler\DM\Expressions\Dereference.cs(295,45): error CS0246: The type or namespace name 'NotNullWhen' could not be found (are you missing a using directive or an assembly reference?)

Could be a problem with your RT submodule because the annotations package is referenced there. no idea otherwise.

@wixoaGit wixoaGit merged commit 1c11807 into OpenDreamProject:master Jan 22, 2024
6 checks passed
@distributivgesetz distributivgesetz deleted the nameof-touchup branch January 22, 2024 21:18
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

Successfully merging this pull request may close these issues.

3 participants