2
0
Эх сурвалжийг харах

emit "Abstract as value" error
instead of "Class<_Abstr_Impl> should be ..." on unification with abstracts
closes #8819

Aleksandr Kuzmenko 6 жил өмнө
parent
commit
bc8c57287b

+ 3 - 1
src/core/error.ml

@@ -34,7 +34,9 @@ let short_type ctx t =
 	let tstr = s_type ctx t in
 	let tstr = s_type ctx t in
 	if String.length tstr > 150 then String.sub tstr 0 147 ^ "..." else tstr
 	if String.length tstr > 150 then String.sub tstr 0 147 ^ "..." else tstr
 
 
-let unify_error_msg ctx = function
+let unify_error_msg ctx err = match err with
+	| Cannot_unify (TType({ t_type = TAnon { a_status = { contents = Statics { cl_kind = KAbstractImpl _ }}}}, _),_) ->
+		"Cannot use abstract as value"
 	| Cannot_unify (t1,t2) ->
 	| Cannot_unify (t1,t2) ->
 		s_type ctx t1 ^ " should be " ^ s_type ctx t2
 		s_type ctx t1 ^ " should be " ^ s_type ctx t2
 	| Invalid_field_type s ->
 	| Invalid_field_type s ->

+ 1 - 1
tests/misc/projects/Issue7526/compile-fail.hxml.stderr

@@ -1,4 +1,4 @@
 Main.hx:16: characters 9-29 : Class<C> should be { member : Int }
 Main.hx:16: characters 9-29 : Class<C> should be { member : Int }
 Main.hx:16: characters 9-29 : The field member is not public
 Main.hx:16: characters 9-29 : The field member is not public
-Main.hx:17: characters 9-29 : Class<_Main.A_Impl_> should be { member : Int }
+Main.hx:17: characters 9-29 : Cannot use abstract as value
 Main.hx:17: characters 9-29 : The field member is not public
 Main.hx:17: characters 9-29 : The field member is not public

+ 7 - 0
tests/misc/projects/Issue8819/Main.hx

@@ -0,0 +1,7 @@
+class Main {
+	static function main() {
+		Type.allEnums(Foo);
+	}
+}
+
+enum abstract Foo(String) {}

+ 1 - 0
tests/misc/projects/Issue8819/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 2 - 0
tests/misc/projects/Issue8819/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:3: characters 17-20 : Cannot use abstract as value
+Main.hx:3: characters 17-20 : For function argument 'e'