From bf9eefa6944e27b95b7c35e2e4447acbe466e084 Mon Sep 17 00:00:00 2001
From: radare <pancake@nopcode.org>
Date: Fri, 31 Jan 2020 16:00:31 +0100
Subject: [PATCH] parser: resolve optional enum type

---
 vlib/compiler/enum.v            |  3 +++
 vlib/compiler/tests/enum_test.v | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/vlib/compiler/enum.v b/vlib/compiler/enum.v
index 5e04e750b2..31da5b74f2 100644
--- a/vlib/compiler/enum.v
+++ b/vlib/compiler/enum.v
@@ -119,6 +119,9 @@ int typ;
 }
 
 fn (p mut Parser) check_enum_member_access() {
+	if p.expected_type.starts_with('Option_') {
+		p.expected_type = p.expected_type[7..]
+	}
 	T := p.find_type(p.expected_type)
 	if T.cat == .enum_ {
 		p.check(.dot)
diff --git a/vlib/compiler/tests/enum_test.v b/vlib/compiler/tests/enum_test.v
index f36064eaab..1decd66a8c 100644
--- a/vlib/compiler/tests/enum_test.v
+++ b/vlib/compiler/tests/enum_test.v
@@ -4,6 +4,21 @@ enum Color {
 	green
 }
 
+fn enum_optional_helper(b bool) ?Color {
+	if b {
+		return .red
+	}
+	return error('failed')
+}
+
+fn test_enum_optional() {
+	a := enum_optional_helper(true) or {
+		assert false
+		return
+	}
+	assert a == .red
+}
+
 fn test_enum() {
 	assert Color.red == .red
 	assert Color.blue == .blue