Support having no getter/setters on a userdata field
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -73,12 +73,13 @@ BoundStatement* Binder::BindAssignmentStatement(const ParsedStatement *statement
|
||||
|
||||
BoundStatement *Binder::BindIndexAssignmentStatement(const ParsedStatement *statement) {
|
||||
auto s = (ParsedIndexAssignmentStatement*) statement;
|
||||
auto boundIndexExpression = this -> BindIndexExpression((IndexExpression*)s->GetIndexExpression());
|
||||
auto boundIndexExpression = this -> BindIndexExpression((IndexExpression*)s->GetIndexExpression(), true);
|
||||
auto valueExpression = this -> BindExpression(s->GetValueExpression());
|
||||
if (boundIndexExpression->GetType()->operator!=(valueExpression->GetType().get())){
|
||||
this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::InvalidTableValueType, statement->GetStartPosition(), statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
|
||||
return new BoundIndexAssignmentStatement(boundIndexExpression, valueExpression);
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ BoundExpression* Binder::BindExpression(const ParsedExpression* expression){
|
||||
return this->BindFunctionCall((FunctionCallExpression*)expression);
|
||||
|
||||
case ParsedExpressionKind ::Indexer:
|
||||
return this->BindIndexExpression((IndexExpression*)expression);
|
||||
return this->BindIndexExpression((IndexExpression*)expression, false);
|
||||
case ParsedExpressionKind::NumericalTable:
|
||||
return this -> BindNumericalTableExpression((ParsedNumericalTableExpression*)expression);
|
||||
case ParsedExpressionKind ::Table:
|
||||
@@ -415,15 +416,34 @@ BoundExpression* Binder::BindFunctionCall(const FunctionCallExpression* expressi
|
||||
expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
||||
BoundExpression *Binder::BindIndexExpression(const IndexExpression *expression) {
|
||||
BoundExpression *Binder::BindIndexExpression(const IndexExpression *expression, bool setter) {
|
||||
auto indexer = this->BindExpression(expression->GetIndexer());
|
||||
auto index = this->BindExpression(expression->GetIndex());
|
||||
|
||||
if (!indexer->GetType()->CanBeIndexedWith(index->GetType().get())){
|
||||
auto indexerType = indexer -> GetType();
|
||||
if (!indexerType->CanBeIndexedWith(index->GetType().get())){
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::CantIndex, index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
if (indexerType -> GetClass() == TypeClass::UserData){
|
||||
auto stringKey = dynamic_pointer_cast<StringScriptType>(index -> GetType());
|
||||
auto field = dynamic_pointer_cast<UserDataScriptType>(indexerType) -> GetField(stringKey->GetHashValue());
|
||||
if (!setter){
|
||||
if (!field->HasGetter()){
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoGetter, index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
} else{
|
||||
if (!field->HasSetter()){
|
||||
this->_scriptData->Diagnostics->LogError(DiagnosticCode::UserDataFieldNoSetter, index->GetStartPosition(),
|
||||
index->GetLength());
|
||||
return new BoundBadExpression(expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto resultType = indexer->GetType()->GetIndexedType(index->GetType().get());
|
||||
return new BoundIndexExpression(indexer, index, resultType, expression->GetStartPosition(), expression->GetLength());
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Binder {
|
||||
BoundExpression *BindBinaryOperator(const BinaryExpression *expression);
|
||||
BoundExpression *BindUnaryOperator(const UnaryExpression *expression);
|
||||
BoundExpression *BindFunctionCall(const FunctionCallExpression *expression);
|
||||
BoundExpression *BindIndexExpression(const IndexExpression *expression);
|
||||
BoundExpression *BindIndexExpression(const IndexExpression *expression, bool setter);
|
||||
BoundExpression *BindNumericalTableExpression(const ParsedNumericalTableExpression *expression);
|
||||
BoundExpression *BindTableExpression(const ParsedTableExpression * expression);
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user