-
Notifications
You must be signed in to change notification settings - Fork 325
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
[gbc] gbc should reject methods with same name #388
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ parseBond :: | |
-> String -- ^ content of a schema file to parse | ||
-> FilePath -- ^ path of the file being parsed, used to resolve relative import paths | ||
-> ImportResolver -- ^ function to resolve and load imported files | ||
-> IO (Either ParseError Bond) -- ^ function returns 'Bond' which represents the parsed abstract syntax tree | ||
-> IO (Either ParseError Bond) -- ^ function returns 'Bond' which represents the parsed abstract syntax tree | ||
-- or 'ParserError' if parsing failed | ||
parseBond s c f r = runReaderT (runParserT bond (Symbols [] []) s c) (Environment [] [] f r) | ||
|
||
|
@@ -240,8 +240,9 @@ struct = do | |
[] -> return fields' | ||
Field {..}:_ -> fail $ "Duplicate definition of the field with ordinal " ++ show fieldOrdinal ++ | ||
" and name " ++ show fieldName | ||
where | ||
findDuplicatesBy accessor xs = deleteFirstsBy ((==) `on` accessor) xs (nubBy ((==) `on` accessor) xs) | ||
|
||
findDuplicatesBy :: (Eq b) => (a -> b) -> [a] -> [a] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this feels like an odd place in the file for such a helper method. Move to near beginning/end? |
||
findDuplicatesBy accessor xs = deleteFirstsBy ((==) `on` accessor) xs (nubBy ((==) `on` accessor) xs) | ||
|
||
manySortedBy :: (a -> a -> Ordering) -> ParsecT s u m a -> ParsecT s u m [a] | ||
manySortedBy = manyAccum . insertBy | ||
|
@@ -410,7 +411,13 @@ service = do | |
local (with params) $ Service namespaces attr name params <$> methods <* optional semi | ||
where | ||
with params e = e { currentParams = params } | ||
methods = braces $ semiEnd (try event <|> try function) | ||
methods = unique $ braces $ semiEnd (try event <|> try function) | ||
unique p = do | ||
methods' <- p | ||
case findDuplicatesBy methodName methods' of | ||
[] -> return methods' | ||
Function {..}:_ -> fail $ "Duplicate definition of the function with name " ++ show methodName | ||
Event {..}:_ -> fail $ "Duplicate definition of the event with name " ++ show methodName | ||
|
||
function :: Parser Method | ||
function = Function <$> attributes <*> payload <*> identifier <*> input | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace tests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: consider naming this file |
||
|
||
struct dummy { | ||
0: int32 count; | ||
} | ||
|
||
// Invalid service definition with two methods with the same name | ||
service Foo | ||
{ | ||
void bar(dummy); | ||
nothing bar(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: "...name are unique with a service."?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
within?