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

Godot C# Parser Fails to Parse Namespace Alias Qualifiers #28293

Open
sethdmoore opened this issue Apr 22, 2019 · 9 comments
Open

Godot C# Parser Fails to Parse Namespace Alias Qualifiers #28293

sethdmoore opened this issue Apr 22, 2019 · 9 comments

Comments

@sethdmoore
Copy link

sethdmoore commented Apr 22, 2019

Godot version:
v3.1.mono.official

OS/device including version:
Windows 10

Issue description:
Cannot compile C# script with namespace alias qualifier.
Using Visual Studio 2019 MSBUILD.

Minimal reproduction project:
Build with following script

using shorthand = System.Collections.Generic;

public class KeyExtension : shorthand::KeyNotFoundException {}

Result

 modules/mono/editor/csharp_project.cpp:183 - Parse error: Unexpected token: :
 Failed to determine namespace and class for script: res://Scripts/Card.cs
 modules/mono/editor/mono_bottom_panel.cpp:168 - Condition ' metadata_err != OK ' is true

Sanity
The above script compiles in Visual Studio Community 2019.
If I change the script from using '::' to a '.', it will compile in Godot.
EG:

using shorthand = System.Collections.Generic;

public class KeyExtension : shorthand.KeyNotFoundException {}

Use Case
We are using protoc (Google's Protobuf) to generate C# files for our Godot project. It generates fine on the Golang backend, but the generated C# code will not compile due to it generating namespace aliases.
EG (partial generated code):

using pb = global::Google.Protobuf;
namespace Card {
  public sealed partial class Card : pb::IMessage<Card> {}
}
@sethdmoore
Copy link
Author

sethdmoore commented Apr 22, 2019

In the off chance that someone else encounters this issue with protobufs and Godot (or they really like namespace alias qualifiers), I've written a python script to alter scripts to satisfy Godot's parser peculiarities.

It's a hack, but it unblocks me for now.

fix_namespace_alias_qualifiers.py�

@sethdmoore
Copy link
Author

Is there any movement on this? We depend on protoc to generate code for C# protobufs, so I find it important to not rely on python hacks.

@jonathancm
Copy link

I can confirm that this is still the case in Godot v3.2.1.

We have a similar setup where we also use Google Protocol Buffer and the generated files contain namespace alias qualifiers. It works fine when we run, but it fails to build.

@Calinou
Copy link
Member

Calinou commented Mar 5, 2020

cc @neikeq

@neikeq neikeq self-assigned this Mar 5, 2020
@neikeq neikeq added this to the 4.0 milestone Mar 5, 2020
@neikeq neikeq added bug and removed enhancement labels Mar 5, 2020
@sylv256
Copy link

sylv256 commented Jul 5, 2020

I'm also encountering a similar issue in Godot v3.2.1. It seems that not all of the components of the Protobuf library are available. I've installed the NuGet package and everything, but no luck. It can't find my compiled protobuf files for some reason.

@Sslaxx
Copy link

Sslaxx commented Apr 25, 2021

This appears to be the case in 3.3 still, if the README for https://github.com/HaxeGodot/godot/ is accurate. @ibilon

@ibilon
Copy link

ibilon commented Apr 25, 2021

Yes I still have that issue in 3.3.
modules/mono/glue/gd_glue.cpp:250 - Failed to determine namespace and class for script: res://build/src/Main.cs. Parse error: Unexpected token: :
with the Haxe generated c# code public class Main : global::Godot.Spatial { (...)
I'll try on godot 4 to see if that's already fixed there.

@ibilon
Copy link

ibilon commented May 1, 2021

Testing on Godot 4, with the class public partial class MyNode : global::Godot.Node2D or the code from the first post, building doesn't show any warning.
I'll take a look if I can make a fix for the parser on 3.3.

@neikeq
Copy link
Contributor

neikeq commented May 1, 2021

We switched to source generators to collect qualified names in Godot 4.
I don't think it's a good idea to keep patching our simple parser in Godot 3.2. If we want to fix those bugs, it may be a better idea to replace it with roslyn there.

@raulsntos raulsntos modified the milestones: 4.0, 3.x Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants