glsl2: Check that returned expressions match the function return type.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 29 Jun 2010 06:38:04 +0000 (23:38 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 29 Jun 2010 18:12:53 +0000 (11:12 -0700)
From my reading of the specification, implicit conversions are not
allowed.  ATI seems to agree, though nVidia allows it without warning.

src/glsl/ast_to_hir.cpp

index 33eb27533fd916f3fd1eb4583c6d2c0682ec7815..45228649adc2a2aa12425d0c4051989c5a85f8fd 100644 (file)
@@ -2151,9 +2151,17 @@ ast_jump_statement::hir(exec_list *instructions,
            opt_return_value->hir(instructions, state);
         assert(ret != NULL);
 
-        /* FINISHME: Make sure the type of the return value matches the return
-         * FINISHME: type of the enclosing function.
-         */
+        /* Implicit conversions are not allowed for return values. */
+        if (state->current_function->return_type != ret->type) {
+           YYLTYPE loc = this->get_location();
+
+           _mesa_glsl_error(& loc, state,
+                            "`return' with wrong type %s, in function `%s' "
+                            "returning %s",
+                            ret->type->name,
+                            state->current_function->function_name(),
+                            state->current_function->return_type->name);
+        }
 
         inst = new(ctx) ir_return(ret);
       } else {