Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-namespace class inheritance transpile bug #990

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/files/BrsFile.Class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,80 @@ describe('BrsFile BrighterScript classes', () => {
program.validate();
});

it('extending namespaced class transpiles properly', () => {
testTranspile(`
namespace App
class CoreClass
sub new()
print "CoreClass.new()"
end sub
end class
end namespace
namespace App.Logic
class FirstClass extends App.CoreClass
end class
class SecondClass extends FirstClass
end class
end namespace
namespace App.OtherLogic
class FinalClass extends App.Logic.SecondClass
end class
end namespace
`, `
function __App_CoreClass_builder()
instance = {}
instance.new = sub()
print "CoreClass.new()"
end sub
return instance
end function
function App_CoreClass()
instance = __App_CoreClass_builder()
instance.new()
return instance
end function
function __App_Logic_FirstClass_builder()
instance = __App_CoreClass_builder()
instance.super0_new = instance.new
instance.new = sub()
m.super0_new()
end sub
return instance
end function
function App_Logic_FirstClass()
instance = __App_Logic_FirstClass_builder()
instance.new()
return instance
end function
function __App_Logic_SecondClass_builder()
instance = __App_Logic_FirstClass_builder()
instance.super1_new = instance.new
instance.new = sub()
m.super1_new()
end sub
return instance
end function
function App_Logic_SecondClass()
instance = __App_Logic_SecondClass_builder()
instance.new()
return instance
end function
function __App_OtherLogic_FinalClass_builder()
instance = __App_Logic_SecondClass_builder()
instance.super2_new = instance.new
instance.new = sub()
m.super2_new()
end sub
return instance
end function
function App_OtherLogic_FinalClass()
instance = __App_OtherLogic_FinalClass_builder()
instance.new()
return instance
end function
`);
});

it.skip('detects calling class constructors with too many parameters', () => {
program.setFile('source/main.bs', `
class Parameterless
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ export class ClassStatement extends Statement implements TypedefProvider {
let stmt = this as ClassStatement;
while (stmt) {
if (stmt.parentClassName) {
const namespace = this.findAncestor<NamespaceStatement>(isNamespaceStatement);
const namespace = stmt.findAncestor<NamespaceStatement>(isNamespaceStatement);
//find the parent class
stmt = state.file.getClassFileLink(
stmt.parentClassName.getName(ParseMode.BrighterScript),
Expand Down