Skip to content

Commit

Permalink
Detect duplicate definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahnfelt committed Dec 25, 2024
1 parent 157f1d7 commit cd27703
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 61 deletions.
9 changes: 6 additions & 3 deletions compiler/Resolver.ff
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ extend self: Resolver {
module.functions.map {self3.resolveFunctionDefinition(_, True, False)}
) {_.signature.name} {_.at}
)
module2.extends.map {x =>
Pair(x.type.show([]).takeWhile {_.isAsciiLetterOrDigit()}, x.methods)
}.group().values().map {_.flatten()}.map {methods =>
checkDuplicates(methods) {_.signature.name} {_.at}
}
module2.instances.each {_.typeArguments.each {self3.checkInstanceType(_)}}
module2
}
Expand Down Expand Up @@ -266,9 +271,7 @@ extend self: Resolver {
definition.DExtend(
constraints = definition.constraints.map {selfWithQ.resolveConstraint(_, True)}
type = selfWithQ.resolveType(definition.type, True)
methods = checkDuplicates(
definition.methods.map {selfWithNoQ.resolveFunctionDefinition(_, True, False)}
) {_.signature.name} {_.at}
methods = definition.methods.map {selfWithNoQ.resolveFunctionDefinition(_, True, False)}
)
}

Expand Down
148 changes: 104 additions & 44 deletions output/js/ff/compiler/Inference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,36 @@ return ff_core_Pair.Pair(ff_compiler_Unification.InstanceKey(c_.name_, typeName_

export function catchMany_(list_, body_) {
const errors_ = ff_core_Array.new_();
const result_ = ff_compiler_Inference.catchManyInto_(errors_, list_, body_);
{
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {
return result_
}
if(_1.length === 1) {
const error_ = _1[0].second_;
return ff_core_Error.Error_rethrow(error_)
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
return
}
}
}

export function catchManyInto_(errors_, list_, body_) {
const result_ = ff_core_List.List_map(list_, ((x_) => {
return ff_core_Try.Try_catch(ff_core_Try.Try_tryCatch(ff_core_Core.try_((() => {
return body_(x_)
})), ((_1, _2) => {
{
const at_ = _1.at_;
const message_ = _1.message_;
const error_ = _2;
errors_.array.push(ff_core_Pair.Pair(compileError_, error_));
errors_.array.push(ff_core_Pair.Pair(ff_compiler_Syntax.CompileError(at_, message_), error_));
return x_
}
}), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError), ((_1, _2) => {
Expand All @@ -165,22 +188,10 @@ return x_
}
}), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)
}));
{
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {
if(ff_core_Array.Array_isEmpty(errors_)) {
return result_
}
if(_1.length === 1) {
const error_ = _1[0].second_;
return ff_core_Error.Error_rethrow(error_)
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
return
}
} else {
return []
}
}

Expand Down Expand Up @@ -215,13 +226,36 @@ return ff_core_Pair.Pair(ff_compiler_Unification.InstanceKey(c_.name_, typeName_

export async function catchMany_$(list_, body_, $task) {
const errors_ = ff_core_Array.new_();
const result_ = (await ff_compiler_Inference.catchManyInto_$(errors_, list_, body_, $task));
{
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {
return result_
}
if(_1.length === 1) {
const error_ = _1[0].second_;
return ff_core_Error.Error_rethrow(error_)
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
return
}
}
}

export async function catchManyInto_$(errors_, list_, body_, $task) {
const result_ = (await ff_core_List.List_map$(list_, (async (x_, $task) => {
return ff_core_Try.Try_catch(ff_core_Try.Try_tryCatch((await ff_core_Core.try_$((async ($task) => {
return (await body_(x_, $task))
}), $task)), ((_1, _2) => {
{
const at_ = _1.at_;
const message_ = _1.message_;
const error_ = _2;
errors_.array.push(ff_core_Pair.Pair(compileError_, error_));
errors_.array.push(ff_core_Pair.Pair(ff_compiler_Syntax.CompileError(at_, message_), error_));
return x_
}
}), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError), ((_1, _2) => {
Expand All @@ -236,42 +270,49 @@ return x_
}
}), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)
}), $task));
{
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {
if(ff_core_Array.Array_isEmpty(errors_)) {
return result_
}
if(_1.length === 1) {
const error_ = _1[0].second_;
return ff_core_Error.Error_rethrow(error_)
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
return
}
} else {
return []
}
}

export function Inference_inferModule(self_, module_, otherModules_) {
const environment_ = ff_compiler_Environment.new_(module_, otherModules_, false);
const traits_ = ff_compiler_Inference.catchMany_(module_.traits_, ((_w1) => {
const errors_ = ff_core_Array.new_();
const traits_ = ff_compiler_Inference.catchManyInto_(errors_, module_.traits_, ((_w1) => {
return ff_compiler_Inference.Inference_inferTraitDefinition(self_, environment_, _w1)
}));
const instances_ = ff_compiler_Inference.catchMany_(module_.instances_, ((_w1) => {
const instances_ = ff_compiler_Inference.catchManyInto_(errors_, module_.instances_, ((_w1) => {
return ff_compiler_Inference.Inference_inferInstanceDefinition(self_, environment_, _w1)
}));
const lets_ = ff_compiler_Inference.catchMany_(module_.lets_, ((_w1) => {
const lets_ = ff_compiler_Inference.catchManyInto_(errors_, module_.lets_, ((_w1) => {
return ff_compiler_Inference.Inference_inferLetDefinition(self_, environment_, _w1)
}));
const functions_ = ff_compiler_Inference.catchMany_(module_.functions_, ((_w1) => {
const functions_ = ff_compiler_Inference.catchManyInto_(errors_, module_.functions_, ((_w1) => {
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, _w1)
}));
const extends_ = ff_compiler_Inference.catchMany_(module_.extends_, ((_w1) => {
const extends_ = ff_compiler_Inference.catchManyInto_(errors_, module_.extends_, ((_w1) => {
return ff_compiler_Inference.Inference_inferExtendDefinition(self_, environment_, _w1)
}));
do {
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {

break
}
if(_1.length === 1) {
const error_ = _1[0].second_;
ff_core_Error.Error_rethrow(error_)
break
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
}
} while(false);
const result_ = (((_c) => {
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, traits_, instances_, extends_, lets_, functions_)
}))(module_);
Expand Down Expand Up @@ -320,7 +361,7 @@ throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Sy
const _1 = definition_;
{
const _c = _1;
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_core_List.List_map(definition_.methods_, ((instanceFunction_) => {
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_compiler_Inference.catchMany_(definition_.methods_, ((instanceFunction_) => {
const methodName_ = instanceFunction_.signature_.name_;
const traitMethodName_ = (ff_core_String.String_reverse(ff_core_String.String_dropWhile(ff_core_String.String_reverse(traitName_), ((_w1) => {
return (_w1 !== 46)
Expand Down Expand Up @@ -2155,21 +2196,40 @@ return instantiated_

export async function Inference_inferModule$(self_, module_, otherModules_, $task) {
const environment_ = ff_compiler_Environment.new_(module_, otherModules_, false);
const traits_ = ff_compiler_Inference.catchMany_(module_.traits_, ((_w1) => {
const errors_ = ff_core_Array.new_();
const traits_ = ff_compiler_Inference.catchManyInto_(errors_, module_.traits_, ((_w1) => {
return ff_compiler_Inference.Inference_inferTraitDefinition(self_, environment_, _w1)
}));
const instances_ = ff_compiler_Inference.catchMany_(module_.instances_, ((_w1) => {
const instances_ = ff_compiler_Inference.catchManyInto_(errors_, module_.instances_, ((_w1) => {
return ff_compiler_Inference.Inference_inferInstanceDefinition(self_, environment_, _w1)
}));
const lets_ = ff_compiler_Inference.catchMany_(module_.lets_, ((_w1) => {
const lets_ = ff_compiler_Inference.catchManyInto_(errors_, module_.lets_, ((_w1) => {
return ff_compiler_Inference.Inference_inferLetDefinition(self_, environment_, _w1)
}));
const functions_ = ff_compiler_Inference.catchMany_(module_.functions_, ((_w1) => {
const functions_ = ff_compiler_Inference.catchManyInto_(errors_, module_.functions_, ((_w1) => {
return ff_compiler_Inference.Inference_inferFunctionDefinition(self_, environment_, _w1)
}));
const extends_ = ff_compiler_Inference.catchMany_(module_.extends_, ((_w1) => {
const extends_ = ff_compiler_Inference.catchManyInto_(errors_, module_.extends_, ((_w1) => {
return ff_compiler_Inference.Inference_inferExtendDefinition(self_, environment_, _w1)
}));
do {
const _1 = ff_core_Array.Array_drain(errors_);
if(_1.length === 0) {

break
}
if(_1.length === 1) {
const error_ = _1[0].second_;
ff_core_Error.Error_rethrow(error_)
break
}
{
const allErrors_ = _1;
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileErrors(ff_core_List.List_map(allErrors_, ((_w1) => {
return _w1.first_
}))), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileErrors)})
}
} while(false);
const result_ = (((_c) => {
return ff_compiler_Syntax.Module(_c.file_, _c.packagePair_, _c.imports_, _c.types_, traits_, instances_, extends_, lets_, functions_)
}))(module_);
Expand Down Expand Up @@ -2218,7 +2278,7 @@ throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Sy
const _1 = definition_;
{
const _c = _1;
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_core_List.List_map(definition_.methods_, ((instanceFunction_) => {
return ff_compiler_Syntax.DInstance(_c.at_, _c.generics_, _c.constraints_, _c.traitName_, _c.typeArguments_, _c.generatorArguments_, ff_compiler_Inference.catchMany_(definition_.methods_, ((instanceFunction_) => {
const methodName_ = instanceFunction_.signature_.name_;
const traitMethodName_ = (ff_core_String.String_reverse(ff_core_String.String_dropWhile(ff_core_String.String_reverse(traitName_), ((_w1) => {
return (_w1 !== 46)
Expand Down
Loading

0 comments on commit cd27703

Please sign in to comment.