about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-01-28 15:16:22 -0800
committerKartik K. Agaram <vc@akkartik.com>2016-01-28 15:16:22 -0800
commit7eec783e6ef16722cfa7e5631bff724742cdefb0 (patch)
treec226b0f6ea2e5a4fa70315607b621e3f2859bf60
parent33399312b258ebfbdb3c33e54bb7c46bb402e4fd (diff)
downloadmu-7eec783e6ef16722cfa7e5631bff724742cdefb0.tar.gz
2613 - better error message when forgetting 'shared'
-rw-r--r--038new.cc28
1 files changed, 21 insertions, 7 deletions
diff --git a/038new.cc b/038new.cc
index 1156bb12..95339edc 100644
--- a/038new.cc
+++ b/038new.cc
@@ -94,21 +94,28 @@ case NEW: {
     raise_error << maybe(caller.name) << "result of 'new' should never be ignored\n" << end();
     break;
   }
-  reagent product(inst.products.at(0));
+  if (!product_of_new_is_valid(inst)) {
+    raise_error << maybe(caller.name) << "product of 'new' has incorrect type: " << inst.to_string() << '\n' << end();
+    break;
+  }
+  break;
+}
+:(code)
+bool product_of_new_is_valid(const instruction& inst) {
+  reagent product = inst.products.at(0);
   canonize_type(product);
+  if (!product.type || product.type->value != get(Type_ordinal, "address")) return false;
   drop_from_type(product, "address");
+  if (!product.type || product.type->value != get(Type_ordinal, "shared")) return false;
   drop_from_type(product, "shared");
   if (SIZE(inst.ingredients) > 1) {
     // array allocation
+    if (!product.type || product.type->value != get(Type_ordinal, "array")) return false;
     drop_from_type(product, "array");
   }
-  reagent expected_product("x:"+type.name);
+  reagent expected_product("x:"+inst.ingredients.at(0).name);
   // End Post-processing(expected_product) When Checking 'new'
-  if (!types_strictly_match(product, expected_product)) {
-    raise_error << maybe(caller.name) << "product of 'new' has incorrect type: " << inst.to_string() << '\n' << end();
-    break;
-  }
-  break;
+  return types_strictly_match(product, expected_product);
 }
 
 //:: translate 'new' to 'allocate' instructions that take a size instead of a type
@@ -229,6 +236,13 @@ recipe main [
 ]
 +mem: storing 0 in location 2
 
+:(scenario new_error)
+% Hide_errors = true;
+recipe main [
+  1:address:number/raw <- new number:type
+]
++error: main: product of 'new' has incorrect type: 1:address:number/raw <- new number:type
+
 :(scenario new_array)
 recipe main [
   1:address:shared:array:number/raw <- new number:type, 5
185'>185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283