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

Code formatting issue with standalone C# files #30841

Open
jbevain opened this issue Oct 30, 2018 · 2 comments
Open

Code formatting issue with standalone C# files #30841

jbevain opened this issue Oct 30, 2018 · 2 comments

Comments

@jbevain
Copy link
Contributor

jbevain commented Oct 30, 2018

Version Used:

Microsoft Visual Studio Community 2017 
Version 15.8.8
VisualStudio.15.Release/15.8.8+28010.2048
Microsoft .NET Framework
Version 4.7.03056

C# Tools   2.9.0-beta8-63208-01

Steps to Reproduce:

  1. Set Visual Studio to perform additional cleanups during formatting.

setting

  1. Create a new standalone file test.cs.
  2. Copy the following into test.cs
using System;

using UnityEngine;
using UnityEditor;

class Camera : MonoBehaviour {

	public void Start() {
	}

	public void Update() {
	}
}
  1. Open the test.cs file in Visual Studio as a standalone C# file outside of a project.

Expected Behavior:

File is formatted to my settings, for example:

using System;

using UnityEngine;
using UnityEditor;

class Camera : MonoBehaviour
{
    public void Start()
    {
    }

    public void Update()
    {
    }
}

Actual Behavior:

File is formatted to my settings, but removes the using statements. For instance:

class Camera : MonoBehaviour
{
    public void Start()
    {
    }

    public void Update()
    {
    }
}

Opening a standalone C# file outside of a project prevents us to know all the references the file needs. If we're reformatting a standalone C# file we probably shouldn't perform cleanups that are potentially destructive.

@jinujoseph jinujoseph added the Bug label Nov 6, 2018
@jinujoseph jinujoseph added this to the 16.0 milestone Nov 6, 2018
@sharwell
Copy link
Member

sharwell commented Nov 6, 2018

@jaredpar This is a compiler bug: the compiler should not report CS8019 when one or more identifiers fails to bind during semantic analysis.

@jaredpar
Copy link
Member

jaredpar commented Nov 8, 2018

CC @gafter pretty sure this has been discussed before and there are good reasons for why we do this. Or possibly bad ones we just can't reasonably fix.

The problem is not going to be limited to identifier binding errors. If the compiler emits pretty much any other error you should not be removing unused namespaces. Any fix to the error is likely to reveal other namespaces that are in use.

@jinujoseph jinujoseph modified the milestones: 16.0, 16.3 Jun 9, 2019
@jcouv jcouv modified the milestones: 16.3, Compiler.Next Jul 13, 2019
@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 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

5 participants