v icon indicating copy to clipboard operation
v copied to clipboard

Can't create an enum named "Color" if glfw is imported

Open scherven opened this issue 7 years ago • 2 comments

V version: V 0.1.21 6890034 OS: MacOS Version 10.15 Beta (19A582a) What did you do?

module main

import glfw

enum Color { 
	black white
}

What did you expect to see? No error

What did you see instead?

.../v/vlib/gx/gx.v:16:20: `Color` has no field `r`
   15| 	// Primary colors

   16| 	Blue   = Color { r: 0, g: 0, b: 255 }

             	            ^
   17| 	Red    = Color { r: 255, g: 0, b: 0 }

   18| 	Yellow = Color { r: 255, g: 255, b: 0 }

It looks like somehow my Color enum is overriding the glfw enum?

scherven avatar Oct 18 '19 18:10 scherven

Similar issue when defining a struct named Vec2

struct Vec2 {
	mut: x, y int
}
...v/vlib/glm/glm.v:56:11: cannot define new methods on non-local type `Vec2`
   55| 

   56| fn (v Vec2) str() string {

                 ^
   57| 	return 'Vec3{ $v.x, $v.y }'

   58| }

scherven avatar Oct 18 '19 23:10 scherven

Fixed.

module main

import gx

enum Color {
        black white
}

fn main() {}

medvednikov avatar Apr 03 '20 20:04 medvednikov