Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: runtime/vm/class_finalizer.cc

Issue 1638923002: Compile-time error if mixing class has a factory (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/language/language_analyzer2.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 2203
2204 Array& functions = Array::Handle(zone); 2204 Array& functions = Array::Handle(zone);
2205 Function& func = Function::Handle(zone); 2205 Function& func = Function::Handle(zone);
2206 // The parser creates the mixin application class with no functions. 2206 // The parser creates the mixin application class with no functions.
2207 ASSERT((functions = cls.functions(), functions.Length() == 0)); 2207 ASSERT((functions = cls.functions(), functions.Length() == 0));
2208 // Now clone the functions from the mixin class. 2208 // Now clone the functions from the mixin class.
2209 functions = mixin_cls.functions(); 2209 functions = mixin_cls.functions();
2210 const intptr_t num_functions = functions.Length(); 2210 const intptr_t num_functions = functions.Length();
2211 for (intptr_t i = 0; i < num_functions; i++) { 2211 for (intptr_t i = 0; i < num_functions; i++) {
2212 func ^= functions.At(i); 2212 func ^= functions.At(i);
2213 if (func.IsGenerativeConstructor()) { 2213 if (func.IsFactory() || func.IsGenerativeConstructor()) {
2214 // A mixin class must not have explicit constructors. 2214 // A mixin class must not have explicit constructors.
2215 if (!func.IsImplicitConstructor()) { 2215 if (!func.IsImplicitConstructor()) {
2216 ReportError(cls, cls.token_pos(), 2216 const char* ctr_kind = func.IsFactory() ? "factory" : "constructor";
2217 "mixin class '%s' must not have constructors\n", 2217 const Script& script = Script::Handle(cls.script());
2218 String::Handle(zone, mixin_cls.Name()).ToCString()); 2218 const Error& error = Error::Handle(
2219 LanguageError::NewFormatted(Error::Handle(),
2220 script, func.token_pos(), Report::AtLocation,
2221 Report::kError, Heap::kNew,
2222 "%s '%s' is illegal in mixin class %s",
2223 ctr_kind,
2224 String::Handle(func.PrettyName()).ToCString(),
2225 String::Handle(zone, mixin_cls.Name()).ToCString()));
2226
2227 ReportErrors(error, cls, cls.token_pos(),
2228 "mixin class '%s' must not have constructors",
2229 String::Handle(zone, mixin_cls.Name()).ToCString());
2219 } 2230 }
2220 continue; // Skip the implicit constructor. 2231 continue; // Skip the implicit constructor.
2221 } 2232 }
2222 if (!func.is_static() && 2233 if (!func.is_static() &&
2223 !func.IsMethodExtractor() && 2234 !func.IsMethodExtractor() &&
2224 !func.IsNoSuchMethodDispatcher() && 2235 !func.IsNoSuchMethodDispatcher() &&
2225 !func.IsInvokeFieldDispatcher()) { 2236 !func.IsInvokeFieldDispatcher()) {
2226 func = func.Clone(cls); 2237 func = func.Clone(cls);
2227 cloned_funcs.Add(func); 2238 cloned_funcs.Add(func);
2228 } 2239 }
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
3260 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); 3271 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields());
3261 field ^= fields_array.At(0); 3272 field ^= fields_array.At(0);
3262 ASSERT(field.Offset() == ByteBuffer::data_offset()); 3273 ASSERT(field.Offset() == ByteBuffer::data_offset());
3263 name ^= field.name(); 3274 name ^= field.name();
3264 expected_name ^= String::New("_data"); 3275 expected_name ^= String::New("_data");
3265 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 3276 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
3266 #endif 3277 #endif
3267 } 3278 }
3268 3279
3269 } // namespace dart 3280 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698