• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 17504812320

05 Sep 2025 09:23PM UTC coverage: 59.904% (+0.08%) from 59.826%
17504812320

push

github

web-flow
Add Escript support for uninitialized class functions (#808)

* update grammar

* AST nodes and test

* Address self-review comments
- Replace `super` comment with something more explanatory
- Rename `make_user_function`

* add class analysis for uninit functions

* fix ast test after disallowing static uninit funcs

* use std::ranges::find_if

* add tests

* use SUPER constant; add test

* Remove unreachable code leftover from #809

Since #809, the super function is only generated for a class when
registering a parent class, and therefore it will always have a body. A
"No base class defines a constructor" will only occur if super was never
generated, and is handled in the "No function linked through
FunctionResolver" section of semantic analyzer.

* Address review comments
- use std::ranges::move instead of move iterators
- use std::is_same_v<> vs std::is_same<>::value
- use switch vs chained ternary conditionals

* update escript guide, create tests that are in escript guide

* add core-changes

* Error on uninit and defined constructor

* Move methods' FunctionLink construction to builder

This allows the error message for the uninit function to have a "See
Also" that point to the defined function.

* Move error checks for uninit and defined functions

These semantic checks should be in the ... SemanticAnalyzer.

* fix typo in core-changes

154 of 168 new or added lines in 7 files covered. (91.67%)

1 existing line in 1 file now uncovered.

43860 of 73217 relevant lines covered (59.9%)

427918.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/pol-core/bscript/compiler/ast/ClassDeclaration.cpp
1
#include "ClassDeclaration.h"
2

3
#include "bscript/compiler/ast/ClassParameterDeclaration.h"
4
#include "bscript/compiler/ast/ClassParameterList.h"
5
#include "bscript/compiler/ast/NodeVisitor.h"
6
#include "bscript/compiler/ast/UninitializedFunctionDeclaration.h"
7
#include "bscript/compiler/ast/UserFunction.h"
8
#include "bscript/compiler/file/SourceFileIdentifier.h"
9
#include "bscript/compiler/model/ClassLink.h"
10
#include "bscript/compiler/model/FunctionLink.h"
11

12
#include <ranges>
13

14
namespace Pol::Bscript::Compiler
15
{
16
ClassDeclaration::ClassDeclaration(
638✔
17
    const SourceLocation& source_location, std::string name,
18
    std::unique_ptr<ClassParameterList> parameters, std::shared_ptr<FunctionLink> constructor_link,
19
    ClassMethodMap methods, Node* class_body,
20
    std::vector<std::shared_ptr<ClassLink>> base_class_links,
21
    std::vector<std::unique_ptr<UninitializedFunctionDeclaration>> uninit_functions )
638✔
22
    : Node( source_location ),
23
      name( std::move( name ) ),
638✔
24
      methods( std::move( methods ) ),
638✔
25
      class_body( class_body ),
638✔
26
      constructor_link( std::move( constructor_link ) ),
638✔
27
      base_class_links( std::move( base_class_links ) )
1,276✔
28
{
29
  children.reserve( 1 + uninit_functions.size() );
638✔
30
  children.push_back( std::move( parameters ) );
638✔
31
  std::ranges::move( uninit_functions, std::back_inserter( children ) );
638✔
32
}
638✔
33

34
void ClassDeclaration::accept( NodeVisitor& visitor )
1,864✔
35
{
36
  visitor.visit_class_declaration( *this );
1,864✔
37
}
1,864✔
38

39
void ClassDeclaration::describe_to( std::string& w ) const
4✔
40
{
41
  fmt::format_to( std::back_inserter( w ), "class-declaration({})", name );
4✔
42
}
4✔
43

44
std::vector<std::reference_wrapper<ClassParameterDeclaration>> ClassDeclaration::parameters()
630✔
45
{
46
  std::vector<std::reference_wrapper<ClassParameterDeclaration>> params;
630✔
47

48
  child<ClassParameterList>( 0 ).get_children<ClassParameterDeclaration>( params );
630✔
49

50
  return params;
630✔
51
}
×
52

53
std::vector<std::reference_wrapper<UninitializedFunctionDeclaration>>
54
ClassDeclaration::uninit_functions()
1,323✔
55
{
56
  std::vector<std::reference_wrapper<UninitializedFunctionDeclaration>> params;
1,323✔
57

58
  // The first child is a `ClassParameterList`, so skip it.
59
  for ( auto& param : children | std::views::drop( 1 ) )
1,465✔
60
  {
61
    params.emplace_back( *static_cast<UninitializedFunctionDeclaration*>( param.get() ) );
142✔
62
  }
63

64
  return params;
1,323✔
NEW
65
}
×
66

67
std::string ClassDeclaration::type_tag() const
709✔
68
{
69
  return fmt::format( "{}@{}", name, source_location.source_file_identifier->pathname );
1,418✔
70
}
71
}  // namespace Pol::Bscript::Compiler
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc