carbon-lang
carbon-lang copied to clipboard
explorer crashes on impl of 'unknown' invalid type expression
package P api;
class LazyNe {
impl LazyNe.Make as true {
}
fn Make();
}
fn Main() -> i32 {
return 0;
}
.../include/c++/v1/optional:911: _LIBCPP_ASSERT 'this->has_value()' failed. optional operator* called on a disengaged value
Moving fn Make() declaration above impl results in COMPILATION ERROR: /tmp/crash.carbon:6: Expected a type, but got fun<Make>
Problem is at: https://github.com/carbon-language/carbon-lang/blob/trunk/explorer/interpreter/type_checker.cpp#L4283
The SimpleMemberAccessExpression in impl is typechecked before the class is typed checked and when FindMixedMemberAndType() is called in it, it assumes the class is, and references the static_type of a member which crashes the program.
Moving fn Make() up above the impl, crash disappears and just gives a compilation error.
@josh11b Loooking through https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#external-impl, is impl LazyNe.Make as true actually invalid because LazyNe.Make shouldn't be allowed there without it being a external impl outside a class? Is this even valid syntax?
(is there concise documentation on what the allowed syntax is for generics?)
@josh11b Loooking through https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#external-impl, is
impl LazyNe.Make as trueactually invalid becauseLazyNe.Makeshouldn't be allowed there without it being aexternal imploutside a class? Is this even valid syntax?(is there concise documentation on what the allowed syntax is for generics?)
The design docs cover the syntax but not in a concise way, since that is not the primary focus. The currently defined rule is that impl LazyNe.Make as ... is syntactically legal outside a class definition, but is semantically invalid unless there is also a declaration that LazyNe.Make is implemented inside its class definition. I believe this is documented in the "forward declaration" section: https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#forward-declarations-and-cyclic-references . Presumably the as true part is illegal since true is not an interface or constraint, though.