Repository: conan-io/conan

Issue:
UnboundLocalError when using VisualStudioBuildEnvironment
I keep getting the following python error when using `VisualStudioBuildEnvironment` with conan 1.3.1.
```python
env_build = VisualStudioBuildEnvironment(self)
UnboundLocalError: local variable 'flags' referenced before assignment
```
I think I found the problem in [conans/client/build/compiler_flags.py Line 99](https://github.com/conan-io/conan/blob/develop/conans/client/build/compiler_flags.py#L99)

It looks like 
```python
elif not vs_toolset:
```
should just be an `else` or `flags` should be initialized to something in the 
```python 
if str(compiler) == 'Visual Studio':
``` 
block.



Discussion:

Resolving patch:
diff --git a/conans/client/build/compiler_flags.py b/conans/client/build/compiler_flags.py
--- a/conans/client/build/compiler_flags.py
+++ b/conans/client/build/compiler_flags.py
@@ -96,7 +96,7 @@ def build_type_flags(compiler, build_type, vs_toolset=None):
                      "RelWithDebInfo": ["-gline-tables-only", "-O2", "-fno-inline"],
                      "MinSizeRel": []
                      }.get(build_type, ["-O2", "-Ob2"])
-        elif not vs_toolset:
+        else:
             flags = {"Debug": ["-Zi", "-Ob0", "-Od"],
                      "Release": ["-O2", "-Ob2"],
                      "RelWithDebInfo": ["-Zi", "-O2", "-Ob1"],


Test patch:
diff --git a/conans/test/build_helpers/visual_environment_test.py b/conans/test/build_helpers/visual_environment_test.py
--- a/conans/test/build_helpers/visual_environment_test.py
+++ b/conans/test/build_helpers/visual_environment_test.py
@@ -3,6 +3,7 @@
 from conans import tools
 from conans.test.utils.conanfile import MockConanfile, MockSettings
 from conans.client.build.visual_environment import VisualStudioBuildEnvironment
+from conans.test.utils.tools import TestClient
 
 
 class VisualStudioBuildEnvironmentTest(unittest.TestCase):
@@ -87,3 +88,63 @@ def test_visual(self):
                       '-I/four/include/path -I/five/include/path',
                 "LIB": "/one/lib/path;/two/lib/path;/three/lib/path;/four/lib/path;/five/lib/path",
             })
+
+    def build_type_toolset_test(self):
+        profile = """
+[settings]
+os=Windows
+compiler=Visual Studio
+compiler.version=15
+build_type=Release
+"""
+        profile_toolset = """
+[settings]
+os=Windows
+compiler=Visual Studio
+compiler.version=15
+compiler.toolset=v141
+build_type=Release
+"""
+        profile_toolset_clang = """
+[settings]
+os=Windows
+compiler=Visual Studio
+compiler.version=15
+build_type=Release
+compiler.toolset=v141_clang_c2
+"""
+        conanfile = """
+from conans import ConanFile, VisualStudioBuildEnvironment
+
+class TestConan(ConanFile):
+    name = "testlib"
+    version = "1.0"
+    settings = "compiler", "build_type", "os"
+
+    def build(self):
+        env_build = VisualStudioBuildEnvironment(self)
+        self.output.info(env_build.flags)
+        """
+        client = TestClient()
+        client.save({"profile": profile,
+                     "profile_toolset": profile_toolset,
+                     "profile_toolset_clang": profile_toolset_clang,
+                     "conanfile.py": conanfile})
+
+        result = {"Debug": "['-Zi', '-Ob0', '-Od']",
+                  "Release": "['-DNDEBUG', '-O2', '-Ob2']",
+                  "RelWithDebInfo": "['-Zi', '-O2', '-Ob1']",
+                  "MinSizeRel": "['-O1', '-Ob1']"}
+        result_toolset_clang = {"Debug": "['-gline-tables-only', '-fno-inline', '-O0']",
+                                "Release": "['-DNDEBUG', '-O2']",
+                                "RelWithDebInfo": "['-gline-tables-only', '-O2', '-fno-inline']",
+                                "MinSizeRel": "[]"}
+
+        for build_type in ["Debug", "Release", "RelWithDebInfo", "MinSizeRel"]:
+            client.run("create . danimtb/testing -pr=profile -s build_type=%s" % build_type)
+            self.assertIn(result[build_type], client.out)
+            client.run("create . danimtb/testing -pr=profile_toolset -s build_type=%s" % build_type)
+            self.assertIn(result[build_type], client.out)
+            client.run("create . danimtb/testing -pr=profile_toolset_clang -s build_type=%s" %
+                       build_type)
+            self.assertIn(result_toolset_clang[build_type], client.out)